如何找到所有的`在BASH`\\字{}之间出现的话吗? [英] How to find all of the words appearing between `\word{}` in BASH?

查看:172
本文介绍了如何找到所有的`在BASH`\\字{}之间出现的话吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的文件:

This \word{is} some text.
This is some \word{more text}.
\word{This} is \word{yet} some more \word{text}.

我需要创建所有的出现\\字的文字列表{和匹配的大括号,} ,例如:

I need to create a list of all of the text that appears between \word{ and the matching closing brace, }, e.g.:

is
more text
This
yet
text


  • 的开幕式和闭幕式括号总是出现在同一行,从来没有跨多行。

  • 其他括号是在文档中present,但没有出现在 \\字{}

    • The opening and closing braces always appear on the same line, never across multiple lines.
    • Other braces are present in the document, but none appear inside \word{}.
    • 我如何打印所有出现在 \\字的文字列表{}

      How can I print a list of all of the text appearing in \word{}?

      推荐答案

      的grep与PCRE能力将做的工作:

      grep with PCRE capabilities will do the job:

      grep -Po "(?<=\\word{)[^}]*(?=})" file
      

      这篇关于如何找到所有的`在BASH`\\字{}之间出现的话吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆