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

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

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.

  1. file 1
  2. peter 10 300
  3. Xavier 12 30
  4. Jack 123 67
  5. Ram 34 57
  6. Jancy 56 34
  7. Thomson 56 67
  8. file2
  9. Jack 23 67
  10. peter 12 39
  11. file3
  12. Jack 123 67
  13. peter 15 45
  14. Thomson 35 430

I would like to get the following output

  1. Xavier 12 30
  2. Ram 34 57
  3. Jancy 56 34

Your suggestions would be appreciated. Thank you.

答案1

得分: 1

这是我的建议:

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

希望有所帮助。

英文:

this is my suggestion:

  1. 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

英文:
  1. $ awk 'FILENAME != "file1" {a[$1]; next} !($1 in a)' file[2-6] file1
  2. Xavier 12 30
  3. Ram 34 57
  4. 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:

确定