2017-11-04 80 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