我有一个文件list.txt,有两列和n行,例如
a1.txt bd.txt
b2.txt g6.txt
.....
我需要多次运行一个命令(list.txt中的每一行一次),每次输入文件都是该行的$1
和$2
。
我在下面尝试这样做,我希望将行指定为变量并在每次循环后递增。
a=1
while $a<=200
do
FILE1=$(awk 'FNR==a{$1}' ./list.txt)
FILE2=$(awk 'FNR==a{$2}' ./list.txt)
./command $FILE1 $FILE2
a=$a+1
done
答案 0 :(得分:3)
比这简单得多:
while read arg1 arg2 rest; do
./command $arg1 $arg2
done < list.txt
不需要awk,更不用说每行的两个awk了。