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
backup spanning multiple DVDs dangral UNIX for Dummies Questions & Answers 0 12-24-2007 02:02 PM
Delete multiple lines containting a variable string using SED. selkirk UNIX for Dummies Questions & Answers 2 04-27-2007 07:08 PM
Need to delete multiple lines in a file. kangdom Shell Programming and Scripting 6 10-16-2006 11:02 AM
delete multiple empty lines whatisthis Shell Programming and Scripting 3 11-09-2005 05:42 PM
Delete multiple lines w/ sed bookoo Shell Programming and Scripting 2 07-25-2003 10:03 AM

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 07-25-2007
radha.kalivar radha.kalivar is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
using sed command to delete a string spanning multiple lines

file1 contains the following data

sssssssssss
firstline
secondline pppppppppp
ssssssssss

Using sed comamnd i am trying to delete firtsline secondline.
so, output should be
sssssssssss
pppppppppp
ssssssssss

I tried in the following the way, but it is not working.
sed s/"firstline[\r\t]secondline"// file1
  #2 (permalink)  
Old 07-25-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Code:
sed -e '/firstline/d' -e '/secondline/d' input_file
  #3 (permalink)  
Old 07-25-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
Quote:
Originally Posted by Shell_Life View Post
Code:
sed -e '/firstline/d' -e '/secondline/d' input_file
I Think this would delete the lines containing the pattern secondline. But the OP wanted to remove the pattern from the line.

I think you can use like

Code:
sed 's/.*line//g' file1
or

sed -e 's/firstline//g' -e 's/secondline//g' file1
  #4 (permalink)  
Old 07-25-2007
radha.kalivar radha.kalivar is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
i forgot to mention, the input file can be

sssssssssss
firstline secondline pppppppppp
ssssssssss
or
sssssssssss
firstline
secondline pppppppppp
ssssssssss

ie firtsline secondline can be on the same line or on different lines, and we should only delete only if we can find both firstline and secondline continueously. otherwise it should be retained
  #5 (permalink)  
Old 07-25-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
Input

Code:
$ >cat file1
sssssssssss
firstline
secondline pppppppppp
ssssssssss

sssssssssss
firstline secondline pppppppppp
ssssssssss
Output
Code:
$ > sed -e 's/firstline//g' -e 's/secondline//g' file1
sssssssssss

 pppppppppp
ssssssssss

sssssssssss
  pppppppppp
ssssssssss
  #6 (permalink)  
Old 07-25-2007
radha.kalivar radha.kalivar is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 5
Acccording to my requirement it should not delete third 'firstline' because there is no 'secondline' string after that. it should delete only if 'firstline secondline' comes contionusly. It can have \n in between.

bash-3.00$cat file1
hello
ssssssssss
firstline
secondline pppppppppp
ssssssssss

sssssssssss
firstline secondline pppppppppp
ssssssssss
firstline ssssssssssss

bash-3.00$ sed -e 's/firstline//g' -e 's/secondline//g' file1
ssssssssss

pppppppppp
ssssssssss

sssssssssss
pppppppppp
ssssssssss
ssssssssssss

bash-3.00$
  #7 (permalink)  
Old 07-25-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Quote:
Originally Posted by radha.kalivar View Post
i forgot to mention, the input file can be

sssssssssss
firstline secondline pppppppppp
ssssssssss
or
sssssssssss
firstline
secondline pppppppppp
ssssssssss

ie firtsline secondline can be on the same line or on different lines, and we should only delete only if we can find both firstline and secondline continueously. otherwise it should be retained
By continuously what does that mean,

line after line

Code:
firstline
secondline
or within a same line

Code:
firstline secondline
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 12:46 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