sed match pattern spanning multiple lines

From thelinuxwiki
Revision as of 02:06, 17 May 2017 by Nighthawk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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