LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   howto remove a particular phrase from a text file? (https://www.linuxquestions.org/questions/linux-newbie-8/howto-remove-a-particular-phrase-from-a-text-file-554868/)

jaggy00 05-18-2007 04:59 AM

howto remove a particular phrase from a text file?
 
i need to remove a little piece of text from a bigger text file. i can find the phrase with grep, but have no idea howto remove it from the file.

any advice appreciated.

druuna 05-18-2007 05:28 AM

Hi,

Sed can do that:

sed -i 's/to be removed//' infile

The above will remove to be removed from the infile and saves it in place (the i- option). Try without the -i option first, output is printed to screen instead.

Hope this helps.

Indiestory 05-18-2007 05:35 AM

could be done with grep,
Code:

cat infile | grep -v [phrase] > outfile

druuna 05-18-2007 05:39 AM

Hi,

True, grep can also remove, but it takes out the whole line, not a part of that line. Depending on what you want, both can be used.

BTW: Use: grep -v "[phrase]" infile > outfile if the grep statement is preferable, it's more resource friendly (only one command instead of 2).

jaggy00 05-18-2007 06:27 AM

This solves the issue. Thank you very much :)


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