加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

获取与特定模式匹配的前n行(使用Linux命令)

发布时间:2020-12-14 01:38:23 所属栏目:Linux 来源:网络整理
导读:我有一个巨大的文件,我想找到一个术语模型.我想将包含单词model的前5行管道传输到另一个文件.如何使用 Linux命令执行此操作? 解决方法 男人grep提到那个 -m NUM,--max-count=NUM Stop reading a file after NUM matching lines. If the input is standard i
我有一个巨大的文件,我想找到一个术语模型.我想将包含单词model的前5行管道传输到另一个文件.如何使用 Linux命令执行此操作?

解决方法

男人grep提到那个

-m NUM,--max-count=NUM
          Stop reading a file after NUM matching lines.  If the  input  is
          standard  input  from a regular file,and NUM matching lines are
          output,grep ensures that the standard input  is  positioned  to
          just  after the last matching line before exiting,regardless of
          the presence of trailing context lines.  This enables a  calling
          process  to resume a search.

所以可以使用

grep model old_file_name.txt -m 5 > new_file_name.txt

不需要管道. grep支持几乎所有你需要的东西.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读