The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to delete text from line starting pattern1 up to line before pattern2? repudi8or Shell Programming and Scripting 5 04-15-2008 09:25 PM
how to delete line with matching text and line immediately after orahi001 UNIX for Dummies Questions & Answers 6 01-15-2008 12:34 AM
Delete first line from any text file ? aungomarin Shell Programming and Scripting 5 05-16-2006 09:42 PM
how to delete away text in a file? forevercalz Shell Programming and Scripting 5 01-08-2006 10:28 PM
delete last line from text file hcclnoodles Shell Programming and Scripting 4 06-25-2002 09:52 AM

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

Join Date: Aug 2005
Posts: 6
Delete line in text file

Hi,
How do I go about deleting a line in a text file. I have used grep to find a particlular word, now how do I delete the line?

so far I got:

grep -i $keyword file.txt
  #2 (permalink)  
Old 08-31-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Did you use the search within this forum ?

Please do so. The rules of the forum says

(5) Search the forums database with your keywords before asking.

Vino
  #3 (permalink)  
Old 08-31-2005
Berserk Berserk is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 6
sorry about that, wont happen again.

so if I use:

sed -e '/$keyword/d' file.txt

would that delete a user entered $keyword from a text file?
  #4 (permalink)  
Old 08-31-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
When you do that, you will not see lines containing the $keyword on the terminal. But that wouldnt delete the keyword from the file. Because you are not redirecting the output to a file.

If you need the change to be permanent, then use

Code:
sed -e '/$keyword/d' file.txt >file.txt.new
If the keyword contains spaces and special characteres, you need to put the -e script within double quotes.

Code:
sed -e "/$keyword/d" file.txt >file.txt.new
Vino
  #5 (permalink)  
Old 08-31-2005
Berserk Berserk is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 6
cheers vino, thanks for your help.
  #6 (permalink)  
Old 11-07-2007
pantera975 pantera975 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 4
I hate to bring up a dead topic but its really relavant to what I need

I need to compare 2 files and output what is the same between the 2 into a 3rd file

old.txt = abc def ghi
new.txt = abc ghi jkl
final.txt = abc ghi

Here is what I have.. Not sure why it won't work. Is it because my diff doesn't get just "jkl def"

Quote:
#!/bin/sh

keyword='diff old.txt new.txt'
sed -e '/$keyword/d' old.txt > final.txt
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 On




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