如何找到从文件到另一个文件的话吗? Linux的 [英] How to find words from a file into another file? Linux

查看:153
本文介绍了如何找到从文件到另一个文件的话吗? Linux的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个文本文件中,我有150个新的保留字。我有拥有大约100,000行另一个文本文件(只提)。

At one text file, I have 150 new reserved words. And I have another text file which has about 100,000 lines (just to mention).

我需要做的是, 搜索每一个属于第一个文件,这些话检查它们是否还是不在第二。

What I need to do is, search for each of these words belonging to the first file and check whether they are or not in the second.


  • 我想过用的grep ,但我找不到如何使用它来读取每个单词在原文。

  • I thought about using "grep" but I could not find how to use it to read each of the words in the original text.

有没有办法做到这一点使用 AWK

Is there any way to do this using AWK?

或任何其他?

目前,谢谢。

大家好,我想这个.SH,但它不工作(显示几乎所有的线)。

Guys, i tried with this .sh but it doesn't work (shows almost every line).

    #!/usr/bin/env sh
    cat words.txt | while read line; do  
      if grep -F "$FILENAME" text.txt
      then
        echo "Se encontró $line"
      fi
    done

另一种方式,我发现是:

Another way i found is:

   fgrep -w -o -f "words.txt" "text.txt"

MMMMM。

推荐答案

您可以使用比fgrep -f

fgrep -f "first-file" "second-file"

或者匹配完整的单词:

OR else to match full words:

fgrep -w -f "first-file" "second-file"

更新:根据的评论:

awk 'FNR==NR{a[$1];next} ($1 in a){delete a[$1]; print $1}' file1 file2

这篇关于如何找到从文件到另一个文件的话吗? Linux的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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