If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Deleting lines from a file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-17-07, 09:20
bufsn bufsn is offline
Registered User
 
Join Date: Jun 2005
Posts: 17
Deleting lines from a file

sed '/^[HS]/ d' command will delete all the lines from a file which starts with 'H' or 'S'. But I want to delete all the lines that start with 'H' or 'SLSC' . Can anyone please let me know how to do it?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 05-17-07, 14:44
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Code:
sed '/^H/d' '/^SLSC/d' file
You can combine different expressions in one sed command. Check your man pages for the exact syntax. In Linux e.g. for a command with several expressions every expression has to be preceded by the -e flag.

Regards
Reply With Quote
  #3 (permalink)  
Old 05-17-07, 15:01
bufsn bufsn is offline
Registered User
 
Join Date: Jun 2005
Posts: 17
Thanks.
I cant get it to work. My actual purpose is different. I want to copy all the lines starting with 'H' or 'SLSC' to a new file.

if it is 'H' or 'S', sed '/^[HS]/ !d' file1 > file2 will do.
but i dont know how to do 'H' and 'SLSC' together. I dont want 'S' alone .
I want to copy all the lines starting with 'H' or 'SLSC' to the second file.

Last edited by bufsn; 05-17-07 at 15:11.
Reply With Quote
  #4 (permalink)  
Old 05-17-07, 16:14
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
In that case forget my previous example and try:
Code:
sed -ne '/^H/p' -e '/^SLSC/p' file1 > file2
This works in Linux and AIX and probably in all the other flavours...

Regards
Reply With Quote
  #5 (permalink)  
Old 05-17-07, 16:29
bufsn bufsn is offline
Registered User
 
Join Date: Jun 2005
Posts: 17
Thanks. It works.
Reply With Quote
  #6 (permalink)  
Old 09-11-07, 09:43
ranga2727 ranga2727 is offline
Registered User
 
Join Date: Sep 2007
Posts: 11
Hi .. just to add on this ..

i need to find a word example:coys111 once this string is found .. need to delete the lines which are 5 lines above and 4 lines which are below !!!

Can anyone help me on this >>>
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On