Issue
I am trying to substitute below string with a space and save it to a file.
*wrap*_trig[0]
I tried below sed cmd but it not working. What is going wrong over here.
sed -i 's/*wrap\*_trig[0\]/ /g' file.txt
Solution
This might work for you (GNU sed):
sed 's/\*wrap\*_trig\[0\]/X/g' file
Remember *
and [...]
are metacharacters on the LHS of a substitution command and if literal must be escaped/quoted either by a prefixing a \
or by surrounding the character by [
and ]
. An *
and ]
need not be quoted when there is no character preceding the first or no opening [
with the second.
Here are some more solutions:
sed 's/[*]wrap[*]_trig[[]0[]]/ /g' file
or
sed 's/*wrap\*_trig\[0]/ /g' file
Answered By - potong Answer Checked By - Robin (WPSolving Admin)