这里就是我想要做: 我有一个出了以下命令:同时读两行作为一个字符串变量
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.
这工作,但我会用命令 - 分组以使得发生的事情更清楚一些,例如'while {read -r first;读-r秒; }做'。 – 2012-07-08 09:14:16
这工作太棒了,谢谢你的建议CodeGnome我使用了相同的。 – phani 2012-07-08 15:33:06