【问题标题】:Cygwin - grep ( if file contains )Cygwin - grep(如果文件包含)
【发布时间】:2017-02-24 14:20:31
【问题描述】:

好的,基本上我有一个电子邮件列表

EMAILS.TXT

然后我还有一堆 .txt 文件,其中包含电子邮件:电话号码:姓名

Compiled1.txt
Compiled2.txt
Compiled3.txt
...

我可以使用 grep 或 gawk 来搜索包含已编译 1、已编译 2 的文件夹,以查看行是否包含来自 .txt 文件的电子邮件?

例子

email.txt Contains " example@example.com " & " example1@example1.com "

文件夹包含

Compiled1.txt & Compiled2.txt have both these lines

如果 Cygwin/Gnuwin 包含从 emails.txt 中指定的行,则从compiled1 和compiled2 输出行

Output > example@example.com:000000:ExampleUser 
         example1@example1.com:00010101:ExampleUser2
         ...

【问题讨论】:

    标签: awk grep gawk


    【解决方案1】:

    你可以使用

    grep -Fi -f EMAILS.TXT Compiled*.txt
    

    -f EMAILS.TXT 使用 EMAILS.TXT 的行作为搜索模式。
    -F 禁用对符号的特殊处理,例如 .?
    -i 不区分大小写搜索。

    输出格式为

    File-in-which-a-match-was-found:Matched-line-from-that-file
    

    以你的例子为例:

    Compiled1.txt:example@example.com:000000:ExampleUser
    Compiled1.txt:example1@example1.com:00010101:ExampleUser2
    Compiled2.txt:example@example.com:000000:ExampleUser
    Compiled2.txt:example1@example1.com:00010101:ExampleUser2
    

    如果您也对行号感兴趣,请将-n 添加到命令中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 2012-10-06
      • 1970-01-01
      • 2013-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多