Quantcast
Channel: harsh – Harsh J
Viewing all articles
Browse latest Browse all 10

GNU egrep does not support the \d shorthand

$
0
0

I learnt this the hard way (and said hello to a large living world of non-standard regex implementations). The GNU grep/egrep documentation page documents all their special backslash character support but \d is not one of them.

That is, the following will not work when trying to match a numeric digit at the beginning of file (for example):

egrep '^\d' file.log

You need to use either of these two alternative forms instead:

egrep '^[:digit:]' file.log (OR,)
egrep '^[0-9]' file.log


Viewing all articles
Browse latest Browse all 10

Trending Articles