Kishore
Kishore

Reputation: 1

interval regular expression in awk doesnt work as expected

I have a bunch of files that have comma separated fields and I'm on redhat linux. I'm executing the following awk command like this:

 awk  --re-interval -F "," '$4~/xyz:8080\/proxyval\/getPages.do\?fd=1d[0-9]{1}/ { print }' *

204:1,204,null,xyz:8080/proxyval/getPages.do?fd=1d7d7 ----> dont expect to see this 
204:1,204,null,xyz:8080/proxyval/getPages.do?fd=1d8
204:1,204,null,xyz:8080/proxyval/getPages.do?fd=1d8d8  ----> dont expect to see this   
204:1,204,null,xyz:8080/proxyval/getPages.do?fd=1d3

The fd=1d[0-9]{1} part of regxp should match only fd=1d8 fd=1d3 but it seems to match fd=1d7d7 and 'fd=1d8d8' also. Please let me know If I'm missing something here.

Thanks in advance Regards

Upvotes: 0

Views: 141

Answers (1)

Amadan
Amadan

Reputation: 198324

Regexp matches find substrings, not whole strings; to find an exact match, you must anchor the start (^) and end ($) of string. [0-9]{1} is equivalent to [0-9] (one character from 0 to 9).

I.e. fd=1d[0-9]{1} will find blahfd=1d8732, with the matched region being fd=1d8; ^fd=1d[0-9]$ will not match it, but will match fd=1d8.

Upvotes: 1

Related Questions