【问题标题】:Find a pattern in a file and any files that file references在文件和文件引用的任何文件中查找模式
【发布时间】:2015-08-08 00:56:06
【问题描述】:

假设我有一个文件 foo.txt,我想搜索“bar”,但我也想搜索 foo.txt 包含的任何文件。例如:

foo.txt:

blah
blahblah.txt
bar
bar.txt
/user/john/baboon.txt

blahblah.txt:

monkey
bar
giraffe

bar.txt:

elephant
bar zebra
hippo

/user/john/baboon.txt:

lion
leopard

它返回类似的东西

foo.txt line 3: bar
foo.txt line 4: bar.txt
blahblah.txt line 2: bar
bar.txt line 2: bar zebra

我玩过 grep,我想我以前见过类似的东西

【问题讨论】:

  • 如何知道foo.txt中的内容是文件还是单词?
  • 类似于如何尝试在 vim 中转到文件 (gf)?我也不确定它是如何工作的

标签: grep find


【解决方案1】:

如果所有文件都有后缀.txt

grep -n bar $(grep '(.*).txt$' foo.txt) foo.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    • 2012-03-06
    • 2021-09-06
    相关资源
    最近更新 更多