これが私がやろうとしていることです:私は次のコマンドを持っています:
result=`awk /^#.*/{print;getline;print} file1.txt
echo "$result"
出力は次のとおりです。
#first comment
first line
#second comment
second line
#third comment
third line.
$result を while ループに入れ、2 行を 1 つの文字列変数としてキャプチャして出力する必要がある場合、どうすればよいですか?
例:
echo "$result" | while read m
do
echo "Value of m is: $m"
done
出力は次のとおりです。
Value of m is:#first comment
Value of m is:first line
Value of m is:#second comment
Value of m is:second line
Value of m is:#third comment
Value of m is:third line.
しかし、期待される出力は次のとおりです。
Value of m is:
#first comment
first line
Value of m is:
#second comment
second line
Value of m is:
#third comment
third line.