【问题标题】:grep first n rows, return file name onlygrep 前 n 行,仅返回文件名
【发布时间】:2015-06-18 21:06:44
【问题描述】:

我可以执行以下操作来搜索我需要的内容并返回文件名: grep -l "mysearchstring" ./*.xml 但是我正在搜索的文件很大,所以这需要很长时间。我正在搜索的字符串将出现在前 200 行中,那么如何仅搜索前 200 行并仍然返回文件名? 谢谢

【问题讨论】:

    标签: regex linux search grep


    【解决方案1】:

    你可以这样做:

    for file in *.xml; do
       head -200 "$file" | grep -q "mysearchstring" && echo "$file"
    done
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 2012-02-04
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      相关资源
      最近更新 更多