Tuesday 15 February 2011

unix - Sed three pattern search -



unix - Sed three pattern search -

say have file below. want 3 pattern search fetching between [ , ] , having search string(111) inside:

msg: [ blah abc blah blah blah.. blah blah.. blah blah.. blah efg blah blah blah blah.. ] msg: [ 111 ] msg: [ 222 ]

i see below printed:

msg: [ 222 ]

i tried pcregrep -m 'msg:.*(\n|.)*]' cant figure out how wanted pattern alone. please advise

sed version

sed '#n /msg: \[/,/]/ { h /msg: \[/ x /]/ { x # next search pattern string s/111/&/p } }' yourfile

posix version --posix on gnu sed

unix sed

No comments:

Post a Comment