2

I have a text file that stores combinations of four numbers in the following format:

Num1,Num2,Num3,Num4
Num5,Num6,Num7,Num8
.............

I have a whole bunch of such files and what I need is to grep for all filenames that contains the pattern described above.

I constructed my grep as follows:

grep -l "{d+},{d+},{d+},{d+}" /some/path/to/file/name

The grep terminates without returning anything.

Can somebody point out what I might be doing wrong with my grep statement?

Thanks

ghoti
  • 41,419
  • 7
  • 55
  • 93
sc_ray
  • 7,385
  • 9
  • 59
  • 94

2 Answers2

2

This should do what you want:

egrep -l '[[:digit:]]+,[[:digit:]]+,[[:digit:]]+,[[:digit:]]+' /some/path/to/file/name
bmk
  • 13,031
  • 5
  • 34
  • 40
  • Great! It works. Do you by any chance know what is wrong with the syntax I used? – sc_ray Mar 20 '12 at 15:29
  • 2
    `{d+}` does not mean *match any number with at least one digit*. That would be `\d+` in *perl* type regexps (grep -P). `[0-9]+` or `[[:digit:]]+` means the same using *extended* regexps (grep -E, egrep). Using *basic* regexps (grep) you could use `[0-9][0-9]*` to get the same result. – bmk Mar 20 '12 at 15:43
2

One way is using a perl regexp:

grep -Pl "\d+,\d+,\d+,\d+" /some/path/to/file/name

In your syntax d is literal. It should be escaping that letter, but is not accepted by grep regular regexp.

Birei
  • 33,968
  • 2
  • 69
  • 79