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
を実行すると、期待どおりの結果が得られます。すべてをまとめてではなく、一度に1つずつコメントをキャプチャする必要があるため、これをループに入れています。