sed - Linux: Remove lines starting with [ -
i know can use grep -v '^#' remove lines starting #
now run issues when try remove [ ie. grep -v '^[' or sed '/^[/ d'
why happening , how can accomplish this?
consider test file:
$ cat brackets keep [remove]
using grep:
$ grep -v '^\[' brackets keep
or:
$ grep -v '^[[]' brackets keep
using sed:
$ sed '/^\[/d' brackets keep
or:
$ sed '/^[[]/d' brackets keep
why
when computer command fails work expected, important @ error message. consider:
$ grep -ve '^[' brackets grep: invalid regular expression
the error message reporting invalid regular expression found. because [
regex-active character: [...]
used define character list. thus, if regex contains unescaped [
, must contain matching ]
. there 2 ways avoid this:
escape it. if
[
regex-active character,\[
treated regular (inactive) character.put in character list.
[[]
character list matches 1 character:[
.
Comments
Post a Comment