Difference between revisions of "sed match pattern spanning multiple lines"

From thelinuxwiki
Jump to: navigation, search
(Created page with "file contents abc def ghi match across 2 lines # cat .abc.txt | sed -n '/abc/N;/def/p' abc def match across 3 lines # cat .abc.txt | sed -n '/abc/N;/def/N;/ghi/p' ...")
 

Latest revision as of 02:06, 17 May 2017

file contents

abc
def
ghi

match across 2 lines

# cat .abc.txt | sed -n '/abc/N;/def/p'
abc
def


match across 3 lines

# cat .abc.txt | sed -n '/abc/N;/def/N;/ghi/p'
abc
def
ghi

the N; tells sed to read the next line past \n and continue the match