Strange grep behaviour on fish shell

880 Views Asked by At
cat > abc.txt <<EOF
2014-04-11 00:00:00
2014-02-19 00:22:00
EOF

When I execute

grep -E :[0-9]{2}: abc.txt

I get

2014-02-19 00:22:00

I was expecting

2014-04-11 00:00:00
2014-02-19 00:22:00

This happens on fish shell (2.4.0), on bash it works fine. I am quite intrigued with whats going on here

1

There are 1 best solutions below

0
On BEST ANSWER

In fish {a,b,c} is an enumerator. Example of use from the documentation:

$ echo input.{c,h,txt}
input.c input.h input.txt

So, your regular expression expands as :[0-9]2::

$ echo :[0-9]{2}:
:[0-9]2:
$ echo :[0-9]{2,3,4}:
:[0-9]2: :[0-9]3: :[0-9]4:

Escape the curly braces to avoid this:

$ echo :[0-9]\{2\}:
:[0-9]{2}:

Or, as suggested by Fredrik, quote the whole regular expression:

$ echo ':[0-9]{2}:'
:[0-9]{2}: