LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command erase lines (https://www.linuxquestions.org/questions/linux-newbie-8/command-erase-lines-322744/)

paraiso 05-12-2005 09:59 AM

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

Matir 05-12-2005 10:04 AM

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

paraiso 05-12-2005 10:16 AM

Thanks a lot Matir for the vegetarian pizza :D 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 :)

Matir 05-12-2005 10:41 AM

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?

paraiso 05-12-2005 10:48 AM

Enjoy your lunch Matir :p ! here it's more time for diner

Thanks again for helping


All times are GMT -5. The time now is 02:37 PM.