delete line in file with sed | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

delete line in file with sed

Shell Programming and Scripting


Tags
sed delete line

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-16-2006
forever_49ers forever_49ers is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 19 September 2006, 7:23 PM EDT
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
delete line in file with sed

sed "/$titlesearch/d" movielist

will delete any line in the file movielist that matches $titlesearch, but this is only a screen print correct ?

how can I have sed to actually delete the line from the file so that it doesnt appear next time I open the file ?

thanks
Steffen
Sponsored Links
    #2  
Old 09-16-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 2 September 2014, 5:08 PM EDT
Location: Foxborough, MA
Posts: 7,644
Thanks: 150
Thanked 577 Times in 542 Posts
Quote:
Originally Posted by forever_49ers
sed "/$titlesearch/d" movielist

will delete any line in the file movielist that matches $titlesearch, but this is only a screen print correct ?

how can I have sed to actually delete the line from the file so that it doesnt appear next time I open the file ?

thanks
Steffen

Code:
(echo "g/${titlesearch}/d"; echo 'wq') | ex -s movielist

Sponsored Links
    #3  
Old 09-16-2006
forever_49ers forever_49ers is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 19 September 2006, 7:23 PM EDT
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
thanks,

you mind explaining your code for me, since I am not quite sure what it does

thanks a lot
Steffen
    #4  
Old 09-16-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 2 September 2014, 5:08 PM EDT
Location: Foxborough, MA
Posts: 7,644
Thanks: 150
Thanked 577 Times in 542 Posts
Quote:
Originally Posted by forever_49ers
thanks,

you mind explaining your code for me, since I am not quite sure what it does

thanks a lot
Steffen
it feeds 2 lines into the 'ex' utility:

Code:
# this line does the 'delete'
"g/${titlesearch}/d"
AND
# this line 'Writes' the file to disk and 'Quits' editing the file
'wq'

'man ex' for more options
Sponsored Links
    #5  
Old 09-19-2006
forever_49ers forever_49ers is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 19 September 2006, 7:23 PM EDT
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
that did not work.

ex: command not found

Steffen
Sponsored Links
    #6  
Old 09-19-2006
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 31 July 2014, 8:46 AM EDT
Location: Bangalore,India
Posts: 2,089
Thanks: 12
Thanked 131 Times in 126 Posts
sed "/$titlesearch/d" movielist >tmp
mv tmp movielist
Sponsored Links
    #7  
Old 09-19-2006
forever_49ers forever_49ers is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 19 September 2006, 7:23 PM EDT
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
thats way better, thanks

Steffen
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Delete line from file using ksh Poonamol Shell Programming and Scripting 6 10-15-2010 08:10 AM
Delete first line from file and more.... dfb500 Shell Programming and Scripting 6 07-02-2009 10:04 AM
Delete a line from a file rohini UNIX for Dummies Questions & Answers 8 01-07-2009 05:34 AM
How to delete line from a file ramezernest UNIX for Dummies Questions & Answers 0 11-01-2007 11:56 AM
Delete line(s) from file elchalateco UNIX for Dummies Questions & Answers 4 10-11-2002 01:25 PM



All times are GMT -4. The time now is 05:20 PM.