【发布时间】:2014-08-01 12:43:30
【问题描述】:
给定一个文件integers,其中包含由新行分隔的整数。例如:
1
39
77
109
137
169
197
229
261
293
可以使用以下代码遍历文件:
while read a
do
echo "$a"
done < integers
不过,我正在寻找一种优雅的解决方案,让循环一次接受两个整数,并且总是一步一步更新,这样:
while #some funny commands
do
echo "$a | $b"
done < integers
结果:
1 | 39
39 | 77
77 | 109
109 | 137
137 | 169
169 | 197
197 | 229
229 | 261
261 | 293
【问题讨论】:
-
@AvinashBabu,@Jayesh:没有那个部分已经工作了。我想遍历一个文件,以便在
i-th 迭代中$a包含i-th 行和$bi+1-th 行。