zwlayer zwlayer - 1 year ago 89
Linux Question

Why Sed cannot replace lines that contains . + and *

I have a large file and some of the lines are as follows:

.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*


I want to replace ....+UNKNOWN part with the
...+PUNCT


To do that, I did the following:

sed 's/\.\.\.\.\+\*UNKNOWN\*/\.\.\.\+PUNCT/g' myfile.out > myfile_result.out


However, none of the lines gone.

grep -F '...+*UNKNOWN*' myfile.out

.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*
.... ....+*UNKNOWN*


I couldn't find my error, could you help me about ?

Answer Source

In some versions of sed, \+ has a special meaning, use + to match the plus literally.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download