LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed not working as advertised (https://www.linuxquestions.org/questions/linux-newbie-8/sed-not-working-as-advertised-4175511050/)

battles 07-14-2014 08:59 AM

sed not working as advertised
 
I need to remove a line in a file that contains a word within the line. I know how to do this with grep, but this example was on a site that was also supposed to do this in place:

sed -i -e '/word/d' <f1> # delete line containing 'word' in file in place

What this does is delete the 'word' out of the line, not delete the whole line.
Is this possible to do with sed in place?

Thanks

rknichols 07-14-2014 10:06 AM

What version of sed are you using? In any version I've seen, that deletes the whole line. Please show an example.

battles 07-14-2014 02:05 PM

GNU sed version 4.2.1

I tried it again with a test file and it did indeed remove the whole line. It only removes the word in certain files. Apparently the file type makes a difference. The file looked looked like a text file, but I could only get it to remove the search text.

grail 07-15-2014 08:41 AM

If I were a betting man I would say the files where it behaves unusually are created on Windows as sed has no concern about the file assuming it is regular text


All times are GMT -5. The time now is 05:25 PM.