regex - Sed: Why does [^\]] not seem to work? -
i trying match/output text before first ]
appeared:
sed -i -r 's/^([^\]]*).*/\1/' "$file.tmp"
which surprisingly not work.
however, searching other bracket work:
sed -i -r 's/^([^\[]*).*/\1/' "$file.tmp"
is sed bug or doing wrong?
i know can work around using .*?
enough issue had me stumped long enough i'd know if there missed.
(according --version, using gnu sed 4.2.2.)
you don't need quote closing bracket ]
. in fact regular expression parsed [^\]
followed stray ]
.
you want use following regular expression (note lack of quoting \
):
sed -i -r 's/^([^]].*).*/\1/' "$file.tmp"
the second regular expression works chance because [
has no special meaning in []
expression you'll find match lines start \
.
in fact, when using ]
in []
group, must first character, or second if first 1 ^
.
Comments
Post a Comment