此问题在此处已有答案:
Loop through results of sed(2个答案)
Reading lines in a file and avoiding lines with # with Bash(共10个答案)
三年前就关门了。
我希望while循环忽略空白行和包含#的行
我试着在输入文件中包含sed -e 's/#.*$//' -e '/^$/d',并将其管道化到while循环中,但没有成功。
file=$(sed -e 's/#.*$//' -e '/^$/d' foo.txt)
while IFS=: read -r f1 f2 f3 f4; do
Command
done <"$file"
3条答案
按热度按时间hjqgdpho1#
在subshell中运行sed,并将其输出重定向到while循环。
对于任何对这个答案中使用的语法如何工作感兴趣的人,请参阅the bash-hackers' wiki on process substitution,对于为什么这个语法比
sed ... | while read ...
更好,请参阅BashFAQ #24。ddarikpa2#
您可以使用
grep
:xdnvmnnf3#
使用grep -v: