开发者

Grep group of lines

I'd like to traverse a text file a pull out groups of lines at a time. In the example below, I'd like to grep all lines below AAA but stop at bbb (ie all of th开发者_Python百科e 'xxx')

Thanks

example:

-------AAA-------

xxx

xxx

xxx

xxx

xxx

-------bbb--------

yyy

yyy

yyy

yyy

------AAA---------

xxx

xxx

xxx

xxx

------bbb--------

yyy


if you don't care about inclusion of AAA and bbb lines, this should suffice for your example

$ awk '/AAA/,/bbb/' file

if you don't want AAA and bbb lines

$ awk '/bbb/{f=0}/AAA/{f=1;next}f{print}' file

Alternatively, if you have Ruby(1.9+)

$ ruby -0777 -ne 'puts $_.scan(/-+AAA-+(.*?)-+bbb-+/m) ' file
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜