LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sed: Find pattern and delete 5 lines after it (https://www.linuxquestions.org/questions/programming-9/sed-find-pattern-and-delete-5-lines-after-it-797281/)

supersoni3 03-23-2010 07:49 AM

sed: Find pattern and delete 5 lines after it
 
Hello all

I am trying to edit a print file.

For every occurence of the ^L form feed character I need to remove 5 blank lines after it but still keep the ^L.

I am a rare user of sed and am ok with the basics but am struggling with this.

Can anybody point me in the right direction please?

Many thanks
Paul

PMP 03-23-2010 08:42 AM

Code:

sed '/<regex>/{p;N;N;N;N;N;d}' <file>

grail 03-23-2010 09:38 AM

slight change worked for me:

Code:

sed -i '/<regex>/{n;N;N;N;N;d}' <file>
When I tried the above it took out the regex line as well

supersoni3 03-23-2010 11:02 AM

Thank you both - PMP suggestions worked ok for me.

grail 03-24-2010 07:00 AM

Don't forget to mark as SOLVED


All times are GMT -5. The time now is 01:16 PM.