2017-11-04 146 views
0

我有如下的awk命令:写的shell脚本的循环

awk 'FNR==NR{a[$1$2]=$3;next} ($1$2 in a) {print$1,$2,a[$1$2],$3}' ""each line of file 1"" >./awkfile/12as_132l.txt 

和f1.txt内容是:

1sas.txt 12ds.txt 
13sa.txt 21sa.txt 

我想,我的剧本读FIL1的每一行。 TXT,把内容在此awk命令......,而不是“文件1的每一行””中“” ..和执行命令象下面这样:

awk 'FNR==NR{a[$1$2]=$3;next} ($1$2 in a) {print$1,$2,a[$1$2],$3}' 1sas.txt 12ds.txt >./awkfile/12as_132l.txt 



    awk 'FNR==NR{a[$1$2]=$3;next} ($1$2 in a) {print$1,$2,a[$1$2],$3}' 13sa.txt 21sa.txt >./awkfile/12as_132l.txt 

我需要的人但是问题在于我有点奇怪。

回答

0
change the IFS to IFS=' ' and use loop . 
1

这里是片段,其通过从f1.txt行读取2个场线,把它变成可变的,并且在awk

#!/usr/bin/env bash 

while read -r col1file col2file; do 

     # your command goes here 
     # this awk does nothing, replace it with your command 
     awk '{ }' "$col1file" "$col2file" > someoutfile 

done < "f1.txt" 

测试结果使用:

[email protected]:/tmp$ cat f1.txt 
1sas.txt 12ds.txt 
13sa.txt 21sa.txt 

[email protected]:/tmp$ cat test.sh 
while read -r col1file col2file; do 

     echo "col1 : $col1file" 
     echo "col2 : $col2file" 

     # your command goes here 
     # this awk does nothing, replace it with your command 
     # awk '{ }' "$col1file" "$col2file" > someoutfile 

done < "f1.txt" 

[email protected]:/tmp$ bash test.sh 
col1 : 1sas.txt 
col2 : 12ds.txt 
col1 : 13sa.txt 
col2 : 21sa.txt