The \s
regex extension may not be supported by your sed
.
In BRE syntax (which is what sed
speaks out of the box) you do not backslash round parentheses - doing that turns them into regex metacharacters which do not match themselves, somewhat unintuitively. Also, +
is just a regular character in BRE, not a repetition operator (though you can turn it into one by similarly backslashing it: \+
).
You can try adding an -E
option to switch from BRE syntax to the perhaps more familiar ERE syntax, but that still won't enable Perl regex extensions, which are not part of ERE syntax, either.
sed 's/^TIME\[[^][]*\][[:space:]][[:space:]]-(3)-\.*//' myfile.txt
should work on any reasonably POSIX sed
. (Notice also how the minus character does not need to be backslash-escaped, though doing so is harmless per se. Furthermore, I tightened up the regex for the square brackets, to prevent the "match anything" regex you had .*
from "escaping" past the closing square bracket. In some more detail, [^][]
is a negated character class which matches any character which isn't (a newline or) ]
or [
; they have to be specified exactly in this order to avoid ambiguity in the character class definition. Finally, notice also how the entire sed
script should normally be quoted in single quotes, unless you have specific reasons to use different quoting.)
If you have sed -E
or sed -r
you can use +
instead of *
but then this complicates the overall regex, so I won't suggest that here.