On Sat, 13 Dec 2008, igor denisov wrote: > Hi there, > I need to extract part of text between /pat1/ and /pat2/ but /pat2/ may appear > and may not, > awk '{if (/pat2/) /pat1/, /pat2/ {print}' filename > does not work. How to do that in shell?
Do /pat1/ and /pat2/ appear on the same line? If so, you can use perl: perl -p -i -e 's/^.*(pat1.*(?:pat2)?).*$/$1/g' < filename -d