sed match pattern spanning multiple lines

From thelinuxwiki
Jump to: navigation, search

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