LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   delete lines between match (https://www.linuxquestions.org/questions/programming-9/delete-lines-between-match-880834/)

vikas027 05-16-2011 11:25 AM

Quote:

Originally Posted by grail (Post 4357935)
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.


All times are GMT -5. The time now is 10:34 AM.