Unterminated address regex when using sed

I use the command below, but when I run the command on Linux, I get the following error.

sed -n '/^[2015/01/01 03:46/,/^[2015/01/01 03:47/p' < Input.txt sed: -e expression #1, char 42: unterminated address regex 

Help me with this.

+5
source share
3 answers

You need to run away with [ , otherwise it will start its work in the group and select in / in your data.

 sed -n '/^\[2015\/01\/01 03:46/,/^\[2015\/01\/01 03:47/p' Input.txt 

or (thanks to nu11p01n73R)

 sed -n '\|^\[2015/01/01 03:46|,\|^\[2015/01/01 03:47|p' Input.txt 
+5
source

"[" is a special character in a regular expression. You will need to avoid this and use it like:

 sed -n '/^\[2015\/01\/01 03:46/,/^\[2015\/01\/01 03:47/p' Input.txt Output: [2015/01/01 03:46] INFO .... [2015/01/01 03:46] ERROR .... [2015/01/01 03:47] INFO .... 
+1
source

open [ ie \[ and change the sed delimiter to # or to some character other than / , so it will escape you to avoid each /

 sed -n '\#^\[2015/01/01 03:46#,\#^\[2015/01/01 03:47#p' 

Note. I avoid the first octotorp before each pattern so sed can interpret it as a delimiter.

0
source

Source: https://habr.com/ru/post/1210209/


All Articles