LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2010, 07:49 AM   #1
supersoni3
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Rep: Reputation: 0
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
 
Old 03-23-2010, 08:42 AM   #2
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
Code:
sed '/<regex>/{p;N;N;N;N;N;d}' <file>
 
1 members found this post helpful.
Old 03-23-2010, 09:38 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,000

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
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
 
Old 03-23-2010, 11:02 AM   #4
supersoni3
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thank you both - PMP suggestions worked ok for me.
 
Old 03-24-2010, 07:00 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,000

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Don't forget to mark as SOLVED
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed: delete lines after last occurrence of a pattern in a file zugvogel Programming 4 11-17-2009 01:49 AM
[sed || gawk]: find and delete blocks and lines from file Hisu Programming 1 09-16-2008 02:01 PM
Problems defining SED pattern over multiple lines dj_bridges Programming 12 10-31-2007 08:06 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM
replacement with sed: replace pattern with multiple lines Hcman Programming 5 11-18-2004 07:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration