Reputation: 3685
I have the following sed
command ( for replacing certain contents with space/nothing):
sed "s/.* \[test] \(h\[W/L]-.*\)//g" file.log
but this gives me error like:
sed: -e expression #1, char 29: unknown option to `s'
where I'm making the mistake?
2013-12-04 00:00:39,629 INFO [test] (h[W/L]-75) <a>
adasdsdads
asdasdsddsaadsdasds
</a>
2013-12-04 00:00:39,629 INFO [test] (h[W/L]-75) <a>
asdasdsasaasdas
a
asdas
</a>
The required op is:
<a>
adasdsdads
asdasdsddsaadsdasds
</a>
<a>
asdasdsasaasdas
a
asdas
</a>
Upvotes: 0
Views: 54
Reputation: 10039
sed 's#.* \[test] (h\[W/L]-.*)##' file.log
/
in s///
, here #
()
for the litterla use (opposite behaviour than [
)g
option, only 1 occurence per lineUpvotes: 0
Reputation: 780994
You need to escape the /
inside the regexp:
sed "s/.* \[test] \(h\[W\/L]-.*\)//g" file.log
Otherwise, it's treated as the end of the regexp. Another solution is to use a different delimiter, that isn't used in your pattern:
sed "s|.* \[test] \(h\[W/L]-.*\)/||g" file.log
And if you're trying to match literal parentheses, they don't need to be escaped in sed
. It should be:
sed "s|.* \[test] (h\[W/L]-.*)||g" file.log
Upvotes: 3
Reputation: 174706
You could try this sed command.
$ sed 's/.* \[test\] (h\[W\/L\]-.*) *//g' file
<a>
adasdsdads
asdasdsddsaadsdasds
</a>
<a>
asdasdsasaasdas
a
asdas
</a>
<space>*
at the last helps to remove the spaces following the last )
bracket.
Upvotes: 1