Reputation: 1172
I'm trying to use SED to delete lines inside a log file containing the word "DEBUG". DEBUG can be :
The following regex works fine :
(?m)( |^)DEBUG\s
But when I try to use it with sed, there is no effect.
sed '/(?m)( |^)DEBUG\s/d' infile.log > result.txt
I tried to escape somme characters like () or \ or even ^ but without any success. Thanks for your help.
For example, I have a file containing :
...
DEBUG aaaaaaaaaaaaa aaaaa
DEBUG bbbbbbbb bbb bbbb
ccc cccDEBUGcccc cccc cc
dddDEBUG dddd ddd
DEBUGeeee eee eeee
fff fff fff fff ff DEBUG fff
...
So the result expected should be :
...
DEBUG aaaaaaaaaaaaa aaaaa
DEBUG bbbbbbbb bbb bbbb
fff fff fff fff ff DEBUG fff
...
But instead, all lines appears in the result file.
Upvotes: 0
Views: 85
Reputation: 5591
Hi you actually do not need a sed
command here. A egrep command can solve your problem.
egrep " \DEBUG|^DEBUG\ " infile.log > result.txt
Now your output file result.txt would be look like below:-
DEBUG aaaaaaaaaaaaa aaaaa
DEBUG bbbbbbbb bbb bbbb
fff fff fff fff ff DEBUG fff
Upvotes: 1