如何查找包含给定字符串的每个块

时间:2017-07-11 23:48:24

标签: bash awk grep

我有一个包含多个段落的文件。我想拉开段落。

我引用了这个问题

Given line separated blocks of text, how can I return each block which contains a specific keyword?

但解决方案对我不起作用。

以下是我的数据示例

 * This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. (STOP-String-023)

 * This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on.  (Search-String-085)

Here is random text. Here is random text. 

 * This is a block of text it goes on and on. This is a block of text it goes on and on. This is a block of text it goes on and on. (Search-String-035)
Some text here
Some text here

我想将段落开头的文字拉到(Search-String...我该怎么办?

awk -v RS= '/Search-String[^\n]/ text.txt  

命令不起作用。

1 个答案:

答案 0 :(得分:0)

awk -v RS= 'sub(/.*Search-String/,"")' text.txt

如果那不是您想要的,那么请编辑您的问题以澄清您的要求,并提供预期的输出以与您发布的样本输入一起使用。