比较文件基于file1的第一列,并打印在其他文件中不存在的行。

huangapple go评论56阅读模式
英文:

compare the files based on the first column of file1 and print the row which are not in other files

问题

Xavier 12 30
Ram 34 57
Jancy 56 34

英文:

I have 7 files and would like to compare the first column of file1. I want to print the row if the first column's name from file1 does not appear in any other files.

file 1

peter 10  300
Xavier 12  30
Jack   123  67
Ram    34   57
Jancy   56  34
Thomson 56  67

file2

Jack    23  67
peter   12  39

file3 

Jack   123  67
peter  15   45
Thomson  35  430

I would like to get the following output

Xavier 12  30
Ram    34   57
Jancy   56  34

Your suggestions would be appreciated. Thank you.

答案1

得分: 1

这是我的建议:

grep -v $(printf '-e ^%s ' $(cut -d ' ' -f 1 file2 file3 | sort -u)) file1

希望有所帮助。

英文:

this is my suggestion:

grep -v $(printf '-e ^%s ' $(cut -d ' ' -f 1 file2 file3 | sort -u)) file1

Hope that helps.

答案2

得分: 0

$ awk 'FILENAME != "file1" {a[$1]; next} !($1 in a)' file[2-6] file1
Xavier 12 30
Ram 34 57
Jancy 56 34

英文:
$ awk 'FILENAME != "file1" {a[$1]; next} !($1 in a)' file[2-6] file1
Xavier 12  30
Ram    34   57
Jancy   56  34

huangapple
  • 本文由 发表于 2023年7月3日 12:47:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601894.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定