Hi,
Here's my data -
aa
bb
cc
aa
dd
ee
Now I need to find the smallest block surrounded by aa & dd. Following is not helpful -
sed -n '/aa/,/dd/p' file
I need only -
aa
dd
Hi,
Here's my data -
aa
bb
cc
aa
dd
ee
Now I need to find the smallest block surrounded by aa & dd. Following is not helpful -
sed -n '/aa/,/dd/p' file
I need only -
aa
dd
Using awk:
awk '
/aa/{block=x;CAP=1}
CAP{block=block "\n" $0}
/dd/{print substr(block,2); CAP=block=x}' infile