这是我正在尝试做的事情:我有一个以下命令:
result=`awk /^#.*/{print;getline;print} file1.txt
echo "$result"
输出是:
#first comment
first line
#second comment
second line
#third comment
third line.
如果我必须将 $result 放入 while 循环并将两行捕获为一个字符串变量并打印它,我该怎么做?
例子:
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.