在两个文件中返回公共字段 [英] return common fields in two files
本文介绍了在两个文件中返回公共字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个文件,应该比较文件1第1栏与文件2的第1列和结果文件应该是文件2
I have two files, should compare 1st column of file1 with 1st column of file2 and the resultant file should be file2
例如:
-
文件1
file1
香蕉
芒果
土豆
番茄
apple
banana
Mango
potato
tomato
文件2
苹果:果
茄子:蔬菜
老太太的手指:蔬菜
橙色:水果
西红柿:蔬菜
土豆:蔬菜
apple:fruit
brinjal: vegetable
lady's finger: vegetable
orange: fruit
tomato: vegetable
potato: vegetable
结果文件应该是这个样子:
Resultant file should look something like this:
苹果:果
西红柿:蔬菜
土豆:蔬菜
apple:fruit
tomato: vegetable
potato: vegetable
在这个任何想法,将AP preciated
any ideas on this would be appreciated
感谢
推荐答案
无需排序(进程创建以下)
without the need to sort (less process creation)
$ awk -F":" 'FNR==NR{f[$0];next}($1 in f)' file file2
apple:fruit
tomato: vegetable
potato: vegetable
这篇关于在两个文件中返回公共字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文