Sed strip containing mixed text up to some character
I have a line like this:
14: 32: 38,723 [some text] ERROR - still text ......
I want to delete everything, down to (but not including) the first "[" (so the result will be a line starting with [some text] .....)
My reading
's/^.*\d*\s//'
is that it should replace everything with a digit followed by a space, but it seems that it applies the replacement everywhere in the line, i.e. being greedy.
I tried:
's/^.*\s\[//g'
but he cleans it first "["
How do I change the expression to do what I need? Many thanks
+4
Pyderman
source share2 answers
I would apply the following sed command
s/^[^[]*\[/\[/
It replaces everything to the first [
one [
.
$ echo "14:32:38,723 [some text] ERROR - some more" | sed 's/^[^[]*\[/\[/' [some text] ERROR - some more text
+3
Dmitri Chubarov
source shareThis might work for you:
sed 's/[^[]*//' file
+2
potong
source share