【问题标题】:grep word and retrieve the match and the following lines that start with a tabgrep 单词并检索匹配项和以下以制表符开头的行
【发布时间】:2022-01-22 06:53:01
【问题描述】:

我正在将我在工作中使用的一些术语收集到一个文件中:

terms.txt

term 1
    here is the definition
    definition continues

other
    I will explain it here
    blablabla

random word
    etc
    etc
    blabla


我想 grep 例如“术语”并提取定义,定义在下一行并以选项卡开头

我曾尝试使用 grep -iA 3 termhere terms.txt,但我想更准确一些。

【问题讨论】:

    标签: bash grep


    【解决方案1】:

    当文件处于段落模式时,我通常通过以下方式对段落进行 grep,但在 Linux 系统上使用 Perl:

    perl -n00 -e 'print if /term/' file.txt
    

    示例输出如下:

    [user@localhost ~]$ perl -n00 -e 'print if /term/' file.txt
    term 1
        here is the definition
        definition continues
    

    您可以在此处找到有关段落模式的更多详细信息 - https://faculty.math.illinois.edu/~hildebr/computer/perltips.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多