作者:梁梁庆新 | 来源:互联网 | 2022-12-02 12:01
1> James Brown..:
使用awk:
$ awk -F\; 'NR==FNR{a[$1]=$0;next}$1 in a{print a[$1]}' file2 file1
输出:
Thrust;Thrust;BBC Micro;;;;;;;;;;;;;;
Alien Breed Special Edition '92;Alien Breed Special Edition '92;Amiga;;1992;Team 17;Action / Shooter;;;;;;;;;;
amidar;amidar;Arcade-Vertical;;;;;;;;;;;;;;
mario;mario;FBA;;;;;;;;;;;;;;
mspacman;mspacman;Arcade-Vertical;;;;;;;;;;;;;;
Bubble Bobble (Japan);Bubble Bobble (Japan);msx2;;;;;;;;;;;;;;
解释:
awk -F\; '
NR==FNR { # process file2
a[$1]=$0 # hash record to a, use $1 as key
next # process next record
}
($1 in a) { # if file1 entry is found in hash a
print a[$1] # output it
}' file2 file1 # mind the order. this way file1 dictates the output order