The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
grep unix.com with google



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-16-2006
Registered User
 

Join Date: Sep 2006
Posts: 23
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
  #2 (permalink)  
Old 09-16-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,145
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

  #3 (permalink)  
Old 09-16-2006
Registered User
 

Join Date: Sep 2006
Posts: 23
thanks,

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

thanks a lot
Steffen
  #4 (permalink)  
Old 09-16-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,145
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
  #5 (permalink)  
Old 09-19-2006
Registered User
 

Join Date: Sep 2006
Posts: 23
that did not work.

ex: command not found

Steffen
  #6 (permalink)  
Old 09-19-2006
anbu23 anbu23 is online now Forum Advisor  
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,481
sed "/$titlesearch/d" movielist >tmp
mv tmp movielist
  #7 (permalink)  
Old 09-19-2006
Registered User
 

Join Date: Sep 2006
Posts: 23
thats way better, thanks

Steffen
Sponsored Links
Closed Thread

Bookmarks

Tags
sed delete line

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 Off


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



All times are GMT -4. The time now is 02:03 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