【问题标题】:grep list invert [duplicate]grep列表反转[重复]
【发布时间】:2021-09-06 10:24:42
【问题描述】:

如果文件不包含字符串,如何打印文件名?

grep -vl 'string' file

总是打印file,我猜是因为每个文件至少有一行不是string

$ ls
one  two  three  four  five
$ grep -l 'odd' *
one
three
five
$ grep -lv 'odd' *
one
two
three
four
five

但我希望它打印第一个选项的倒数

two
four

【问题讨论】:

  • 答案是grep -L ...

标签: bash terminal grep zsh


【解决方案1】:

根据grep documentation

-L
--files-without-match
抑制正常输出;而是打印通常不会打印输出的每个输入文件的名称。每个文件的扫描在第一次匹配时停止。

所以,你需要使用

grep -L 'odd' *
four
two

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-27
    • 2019-07-05
    • 1970-01-01
    • 1970-01-01
    • 2022-08-04
    • 2018-08-24
    相关资源
    最近更新 更多