-2

我有这些行,每行开始一个单词,然后相等和几个句子,所以我喜欢选择每个部分。例如:

      delete = \account
          user\
          admin
           admin right is good.
      add = \
          nothing
          no out
          input output is not good 
      edit = permission 
          bob
          admin
          alice killed bob!!!

我想选择一个部分,例如:

  add = \
      nothing
      no out
      input output is not good 

我喜欢用正则表达式来做。

4

2 回答 2

0

您的问题有点含糊,但您可以尝试以下...

/\s*(\w+) = ([^=]*\n)*/m

... 取决于最后一节以 \n 结尾的要求。

这通过以下方式起作用:

  • '\s*' 匹配一些可选的前导空格
  • '(\w+)' 捕获部分的名称
  • '=' 匹配空格等于空格分隔符
  • '([^=]*\n)' 然后它会捕获一个不包含等号并以换行符结尾的字符串
  • '*' 并且它会多次执行最后一点

然后需要 m 标志来设置多行。

请参阅以下内容以快速查看为每个匹配项输出的组...

https://regex101.com/r/oDKSy9/1

(注意:根据您使用正则表达式的方式,可能不需要 g 标志。)

于 2016-10-26T13:18:12.883 回答
0

OP的解决方案。

我找到了这个解决方案:

csplit -k fileName '/.*=/' '{*}' 

谢谢@haggisandchips

于 2017-08-20T03:34:25.577 回答