The UNIX and Linux Forums  

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
help me to answer this lo-lp-kl Shell Programming and Scripting 0 05-25-2008 11:45 PM
Answer them if u can... dreambig UNIX for Dummies Questions & Answers 5 12-07-2007 11:14 AM
quick answer DarkestEvil UNIX for Dummies Questions & Answers 9 10-30-2007 06:42 PM
Can anybody answer this..... shivamasam SUN Solaris 3 07-06-2007 02:50 AM
can any one answer ???? mobile01 High Level Programming 2 11-30-2006 12:32 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-28-2007
LaLonde LaLonde is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 4
Is sed the answer?

Hey, I am very new to scripting and could use a bit of help.

I have a situation where I have an ascii file and I want to delete all lines beneath a particular string.

EXAMPLE:

The contents of a file named example.txt looks like the following:

JANUARY
FEBRUARY
MARCH
APRIL
MAY
JUNE
JULY
AUGUST
SEPTEMBER
OCTOBER
NOVEMBER
DECEMBER


Now I want to be able to run a command where it will delete all lines in the example.txt file beneath the "JUNE" line. I assume that this is pretty easy to do, but given my lack of experience I am having trouble figuring this out.

Is sed the answer? If so, what would the exact command be given my example?

The system I will run the command on is a Solaris 10 base install system with no 3rd-party packages installed.

Thank you in advance!

- LaLonde
  #2 (permalink)  
Old 08-28-2007
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,815

Click here for a UNIX.COM search for SED


Quote:
Results 1 - 10 of about 19,000 from www.unix.com for SED. (0.10 seconds)
  #3 (permalink)  
Old 08-29-2007
aajan aajan is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 80
This solution is specific to this file alone:


sed -e '1,5d' -e '7,12d' FileName
  #4 (permalink)  
Old 08-29-2007
aajan aajan is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 80
OR You can use this solution also


sed -e '6!d' FileName
  #5 (permalink)  
Old 08-29-2007
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
You can use any of the two--

cat file1
JANUARY
FEBRUARY
MARCH
APRIL
MAY
JUNE
JULY
AUGUST
SEPTEMBER
OCTOBER
NOVEMBER
DECEMBER


sed -e '1,6!d' file1
or
sed -e '7,12d' file1

Thanks
Namish
  #6 (permalink)  
Old 08-29-2007
Nagabhushan Nagabhushan is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 12
You an use simple script

row_num=grep -n June filename|cut -d ":" -f1

row_num=6 After execution

then

haed -6 filename
  #7 (permalink)  
Old 08-29-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370

Code:
sed "1,/JUNE/!d" example.txt

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:32 AM.


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