14

I am using the below command but while running the command in linux, getting the below 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

KIndly help me on this.

nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52

3 Answers3

11

You need to escape the [, or else it thinks its start of a group, and escape to / 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
Jotne
  • 40,548
  • 12
  • 51
  • 55
2

escape [ i.e. \[ and change sed's delimiter to # or some character other than / so it will avoid you having to escape every /

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

Note: I escape the first octothorpe in front of each pattern so that sed can interpret it as a delimiter.

repzero
  • 8,254
  • 2
  • 18
  • 40
1

"[" is a special character in regex. You would need to escape it 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 ....
SMA
  • 36,381
  • 8
  • 49
  • 73