cat file1
xi=zaoshui jiao=@E0488_5@
chi=fan da qiu=@E0488_3@
gong=zuo you xi @E0977_5@
cat file2
@E0488_3@ @E21562_3@
@E0488_5@ @E21562_5@
@E0977_3@ @E21630_3@
@E0977_5@ @E21630_5@
@E0977_6@ @E21631_1@
Purpose: if $NF in file1 found in file2 $1, than replace $NF in file1 with file2 $2.otherwise, makes no change.
My Code:
awk 'NR==FNR{a[$1]=$2;next}
{split($NF,a,"=");for($NF in a){$NF=a[$NF]}}1' test2.txt test1.txt
But it comes error:
awk: cmd. line:1: NR==FNR{a[$1]=$2;next}{split($NF,a,"=");for($NF in a){$NF=a[$NF]}}1
awk: cmd. line:1: ^ syntax error
Does my code look right? It seems grammar issue happens. How can I improve it?
My expect output:
xi=zaoshui jiao=@E21562_5@
chi=fan da qiu=@E21562_3@
gong=zuo you xi @E21630_5@
$NFas the loop variable. I guess you wantfor (x in a){$x=a[x]}but it's not really clear. Voting to close as typo.ifinstead offor,but the output makes no change compared with the original file1, why ? ` awk 'NR==FNR{a[$1]=$2;next}{split($NF,a,"=");if($NF in a){$NF=a[$NF]}}1'`