如何找到在两个不同的文本文件同样的话和使用bash打印这些行? [英] How to find the same words in two different text files and print those lines using bash?

查看:119
本文介绍了如何找到在两个不同的文本文件同样的话和使用bash打印这些行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本文件。其中包含只有一个字列。几百个字。在每行仅有一个字。第二个含有大量的列的一列。

我需要找到第一个文本文件,该文件是在第二个文本文件中的单词和打印从第二个文本文件,其中这个词,用awk,grep或者其他命令行程序的整个产品线。例如:

文本文件#1:

 汽车

笔记本

文本文件#2:

  32233:FTD笔记本电脑
24342:TGD车
2424:JDJ笔记本

输出:

  24342:TGD车
2424:JDJ笔记本


解决方案

试试这个:

 的grep -Fwf文件1文件2

I have two text files. One contain just one column of words. Hundreds of words. Just one word in every line. The second one contain a lot of columns a row.

I need to find the words from first text file which are in the second text file and print the entire line from second text file where this word is, using awk, grep or other command line program. For example:

Text file #1:

car
house
notebook

Text file #2:

32233: FTD laptop
24342: TGD car
2424: jdj notebook

Output:

24342: TGD car
2424: jdj notebook

解决方案

try this:

grep -Fwf file1 file2

这篇关于如何找到在两个不同的文本文件同样的话和使用bash打印这些行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆