Skip to content
Advertisement

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 ?

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement