The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to delete a first blank line from the file aoussenko Shell Programming and Scripting 4 06-20-2008 12:05 PM
delete blank space in begining of line karthikn7974 Shell Programming and Scripting 4 05-07-2008 04:40 AM
how to delete text from line starting pattern1 up to line before pattern2? repudi8or Shell Programming and Scripting 5 04-15-2008 09:25 PM
how to delete line with matching text and line immediately after orahi001 UNIX for Dummies Questions & Answers 6 01-15-2008 12:34 AM
regex to delete multiple blank lines in a file? fedora Shell Programming and Scripting 6 10-11-2007 04:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-18-2008
one71 one71 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 10
sed: delete regex line and next line if blank

Hi,

I want to write a sed script which from

Code:
batiato:

batiato/giubbe:
pip_b.2.txt
pip_b.3.txt
pip_b.3mmm.txt

bennato:

bennato/peterpan:
123.txt

consoli:
pip_a.12.txt

daniele:

daniele/anna:
abc.txt
procuces

Code:
batiato/giubbe:
pip_b.2.txt
pip_b.3.txt
pip_b.3mmm.txt

bennato/peterpan:
123.txt

consoli:
pip_a.12.txt

daniele/anna:
abc.txt
I would imagine something like:
"if a line containing ":" is followed by an empty line delete both lines (the line with ":" and the empty line)"
i.e. something like in general
if a line containing regex1 is followed (immediately after) by a line containing regex2 delete both lines.

if it would be on one line I would do: sed '/regex1.*regex2/d' -->
how to spread this command on 2 lines? And consider hat in my case regex2 is an empty line ( i.e. ^$).

thanks
  #2 (permalink)  
Old 09-18-2008
one71 one71 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 10
oh yes! this works now!
Thanks a lot and thanks for the explanation too

Last edited by one71; 09-18-2008 at 05:59 AM..
  #3 (permalink)  
Old 09-18-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Sorry, I posted my first reply based on a too cursory reading of your question.

Code:
sed '/:$/!b;N;/:\n$/d' input.txt
Here's a brief explanation:

/:$/!b - if not a line ending with a colon, just skip to the end of the script and print.
N - this is a line ending with a colon; fetch the next line and glue them together.
/:\n$/d - if the combined two lines match this pattern, delete
else, print

The \n thing works differently in different versions of sed, but if it doesn't work, try with a literal newline, with or without a backslash.

Last edited by era; 09-18-2008 at 05:56 AM.. Reason: Note on \n in different versions of sed
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0