英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论