I have a String
/abc/gef \*(cse,fff)
to delete from a file,have to match the full string pattern,tried with
sed -i '//abc/gef \*(cse,fff)/d' filename
but this ends in an error:
sed: -e expression #1, char xx: expected newer version of sed
I also tried the following options but didn't work:
sed -i '/\/abc\/gef \*(cse,fff)/d' filename
sed -i 's|/abc/gef \*(cse,fff)||g' filename
What is the right command for this?
The problem is that both \
(escape character) and *
(0 or more) have a special meaning in regular expressions, so you need to escape them in order to use them as literal characters. Now, the way to escape something is to add a \
before it. So, in order for *
to match a literal asterisk and not mean "0 or more", you would write \*
. Similarly, to escape the \
you would write \\
. Putting this together, we have:
$ cat file
foo
bar
/abc/gef \*(cse,fff)
baz
And:
$ sed '/\/abc\/gef \\\*(cse,fff)/d' file
foo
bar
baz
Note how I have also escaped the /
since //
is the match operator in sed
. This is why we have /\/abc\/gef
and not //abc/gef
. The d
at the end means "delete any line matching this pattern".
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments