cat test.txt
#this is comment
line 1
line 2
#this is comment at line 3
line4
脚本:
result=`awk '/^#.*/ { print }' test.txt `
for x in $result
do
echo x
done
预期输出:
#this is comment
#this is comment at line 3
获取输出:
#this
is
comment
#this
is
comment
at
line
3
但是当我执行这个命令时awk '/^#.*/ { print }' test.txt
,我得到了预期的结果。我将其置于循环中,因为我需要一次捕获每个评论,而不是全部一起捕获。