05-16-2011, 11:25 AM
|
#16
|
Senior Member
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305
Rep:
|
Quote:
Originally Posted by grail
Hi vikas
Basically they are doing the same thing:
Code:
sed -n -e '/text[12]/p' -e '/text1/,/text2/d;p' file
1. '/text[12]/p' - print any lines containing the string 'text1' or 'text2'
2. '/text1/,/text2/d;p' - delete anything from text1 to text2 inclusive and print the rest
Code:
awk '/text1/,/text2/{if(/text[12]/)print;next}1' file
1. /text1/,/text2/ - search between text1 and text2 inclusive, when true go to step 2
2. if(/text[12]/)print;next - if line contains strings 'text1' or 'text2' then print. Whether previous is true or not go to the next record
3. 1 - print all lines not in the boundary test from step 1
Hope that helps
|
Thanks Grail, really appreciate it.
|
|
|