Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
awk:在不同的文件中搜索字符串,然后将结果附加到输出中_Awk - Fatal编程技术网

awk:在不同的文件中搜索字符串,然后将结果附加到输出中

awk:在不同的文件中搜索字符串,然后将结果附加到输出中,awk,Awk,我在下面有file1.txt 30012516|Geralyn|test|1010029|9985|0029|50|00|OneTime|1227065|2013-03-04|||||||Code4 30013017|tamara|test|3440029|1114|029|41|00|OneTime|1239244|2013-03-04|||||||Code3 30015518|daniel|test|3140029L|6440|0029|99|00|OneTime|1239306|2013-

我在下面有
file1.txt

30012516|Geralyn|test|1010029|9985|0029|50|00|OneTime|1227065|2013-03-04|||||||Code4
30013017|tamara|test|3440029|1114|029|41|00|OneTime|1239244|2013-03-04|||||||Code3
30015518|daniel|test|3140029L|6440|0029|99|00|OneTime|1239306|2013-03-03|||||||Code2
30050011|first|test|1240030|1745|030|96|00|OneTime|1284010|2013-02-22|||||||Code1
10010905|madhu|com|5230029|614|029|29|10|OneTime|1293016|2013-03-04|||||||Code5
这是另一个
file2.txt
,其中包含上述
file1.txt

Code1=Results of code1
Code3=Results of code3 
Code2=Results of code2
Code5=Results of code5
Code6=Results of code6
Code4=Results of code4
Code7=Results of code7
Code8=Results of code8
Code9=Results of code9
Code10=Results of code10
awk -F= 'NR==FNR{A[$1]=$2; next} $NF in A{print A[$NF]}' file2.txt FS=\| file1.txt  > output.out
我想使用
awk
命令首先在
file2.txt
中搜索
file1.txt
的最后一个字符串,并附加结果值,如下所示(这应该是最终输出)

我尝试了下面的命令,但它只给出了值,但无法将结果附加到
file1.txt

Code1=Results of code1
Code3=Results of code3 
Code2=Results of code2
Code5=Results of code5
Code6=Results of code6
Code4=Results of code4
Code7=Results of code7
Code8=Results of code8
Code9=Results of code9
Code10=Results of code10
awk -F= 'NR==FNR{A[$1]=$2; next} $NF in A{print A[$NF]}' file2.txt FS=\| file1.txt  > output.out
试试这句话:

 awk -F= 'NR==FNR{a[$1]=$2;next} {for(x in a) if($0~"\\|"x"$"){print $0"|"a[x];break}}' file2 file1
或者对你的陈述稍加修改:

 awk -F= 'NR==FNR{A[$1]=$2; next} $NF in A{print $0,A[$NF]}' file2.txt FS=\| OFS="|" file1.txt