UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 15th, 2005, 01:28 AM
stevefox stevefox is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 12 stevefox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 29 sec
Reputation Power: 0
Question SED help needed

Could someone please tell me the command to deleting a line with a specific word and also deleting all lines below this line? I want this to be done without opening the file itself using SED in HP Unix.

e.g. I have a text file input.txt and with 4 lines of text below:

John 123 A--G
Chris 190 C--T
Mat 098 F--K
Mike 674 B--N
Pat 838 L--U

I want to delete the line which has string "098" and all lines below this line to look like the below:

John 123 A--G
Chris 190 C--T

Reply With Quote
  #2  
Old November 15th, 2005, 04:43 AM
iribach iribach is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 iribach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 31 m 47 sec
Reputation Power: 0
Quote:
Originally Posted by stevefox
Could someone please tell me the command to deleting a line with a specific word and also deleting all lines below this line? I want this to be done without opening the file itself using SED in HP Unix.

e.g. I have a text file input.txt and with 4 lines of text below:

John 123 A--G
Chris 190 C--T
Mat 098 F--K
Mike 674 B--N
Pat 838 L--U

I want to delete the line which has string "098" and all lines below this line to look like the below:

John 123 A--G
Chris 190 C--T

not really easy, in this case try
sed '/space098space/,$d' inputfile >outputfile
NOTA space is to replace by a space
NOTA this works only in this case, assumed you want delete all
after ' 098 '

Reply With Quote
  #3  
Old November 15th, 2005, 05:54 PM
stevefox stevefox is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 12 stevefox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 29 sec
Reputation Power: 0
Thanks iribach!
It worked!

Reply With Quote
  #4  
Old November 15th, 2005, 07:20 PM
stevefox stevefox is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 12 stevefox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 42 m 29 sec
Reputation Power: 0
Question

Could someone tell me how to make a Korn Shell to do the below:

I have the files below with the same format (different data) as mentioned previously and I want a shell to run "sed '/098/,$ d' filename" on all of the files in the directory.

list20051001.txt
list20051002.txt
list20051003.txt
...
list20051031.txt

Reply With Quote
  #5  
Old November 16th, 2005, 02:56 AM
iribach iribach is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 iribach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 31 m 47 sec
Reputation Power: 0
Quote:
Originally Posted by stevefox
Could someone tell me how to make a Korn Shell to do the below:

I have the files below with the same format (different data) as mentioned previously and I want a shell to run "sed '/098/,$ d' filename" on all of the files in the directory.

list20051001.txt
list20051002.txt
list20051003.txt
...
list20051031.txt

a) mkdir savedfiles
b) cp list2005* savedfiles
c) for file in list2005*
do sed WHATyouWANT savedfiles/$file >$file
done

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > SED help needed


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT