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:

  1. escape it. if [ regex-active character, \[ treated regular (inactive) character.

  2. put in character list. [[] character list matches 1 character: [.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -