I have
text text text [text text] \n
text text text [text text] \n
I want
text text text \n
text text text \n
What RE can I use?
I have
text text text [text text] \n
text text text [text text] \n
I want
text text text \n
text text text \n
What RE can I use?
/[^\[]*/
gets you most of the way. If nothing ever appears after [...], then it is sufficient.
The following works regardless of whether the \n
is the end of line or a backslash and a letter 'n':
sed 's/\[.*] //' $file
The pattern looks for an open square bracket followed by any sequence of characters up to the last close square bracket and a following space (if there are several). You could refine the '.*
' into '[^]]*
' to match anything that is not a close square bracket; this only deletes to the first close square bracket.
you can use awk
$ more file
text [dont want text here ] text text [ dont want text] \n
text text text [ dont want text] \n
$ awk -vRS=']' '/\[/{gsub(/\[.*/,"")}1' ORS="" file
text text text \n
text text text \n