LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-12-2005, 10:59 AM   #1
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Rep: Reputation: 15
Command erase lines


How could I get rid of the lines in a file that contain a specific word ?

for instance directory:

/home/stuff: directory
/home/other: data
/home/down: empty


Cheers
 
Old 05-12-2005, 11:04 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 122Reputation: 122
Use the -v option to grep. Suppose you have a file called "pizza.toppings" containing a list of (what else?) pizza toppings, and you want to remove 'sausage' from the file, you just need to:
Code:
grep -v sausage pizza.toppings > pizza.toppings.without.sausage
 
Old 05-12-2005, 11:16 AM   #3
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Thanks a lot Matir for the vegetarian pizza that's exactly what I needed!

I was trying something else but your method is much better


Code:
sed '/directory/d' list_file > new_file

Cheers
 
Old 05-12-2005, 11:41 AM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 122Reputation: 122
sed would work as well, but I think grep is just a much more direct way to do things.

And can you tell how ready I am to go to lunch?
 
Old 05-12-2005, 11:48 AM   #5
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Enjoy your lunch Matir ! here it's more time for diner

Thanks again for helping
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
erase all the lines of a file Prasun1 Linux - General 9 11-06-2005 11:53 AM
When command lines go bad bob7 Linux - General 3 09-11-2005 06:47 AM
Combining 2 command lines satimis Programming 6 10-18-2004 10:40 PM
Grip command lines linuxtakemeaway Linux - Newbie 5 02-03-2003 02:11 PM
command lines? rockin chair Linux - General 5 04-28-2002 11:48 PM


All times are GMT -5. The time now is 10:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration