Help with NAWK regular expressions

I've a file
$ cat size
1234
5678
vamsi

I want to match the lines which has just 4 digits and nothing else.
So
$ cat size | nawk ' $0 ~ /[0-9][0-9][0-9][0-9]/ {print}'
1234
5678

But when I use the repetition clause it doesn't work
cat size | nawk ' $0 ~ /[0-9]{4}/ {print}'

I actually want to filter out the lines with just 9 digits , but in a elegant manner.
Of course, /[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/ will work, but is there any other possible way?? Thanks in advance!! :smiley:

Use the reinterval argument. The use of cat is redundant:

nawk reinterval '$0 ~ /[0-9]{9}/' size

Regards

This is actually i am doing...

BEGIN {
errcount=0;
RC=0;
print "" > "output"
      }
{

if( $0 ~ /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/)
        {
        print >>"output";
        }

else if($0 ~ /^[0-9][0-9][0-9][0-9][0-9][0-9]$/)
        {
        print $0 "000" >>"output";
        }
else {
      errcount++;
     }
}

END {
if(errcount!=0)
RC=1;
exit RC;
    }

could you please tell me how to use the re interval thing here??

Something like:

#!/bin/sh

nawk reinterval 'BEGIN {..}
}
.
.
.
}
END{...}
' size

Regards

:frowning:
$ nawk --re-interval '$0 ~ /[0-9]{9}/' data
nawk: unknown option --re-interval ignored

:frowning: it's not working..
working on SunOS 5.9.. any clues?

That's because your nawk interpreter is not a GNU awk interpreter.
re-interval is a GNU AWK extension.

This what worked on SunOS, to filter out the records with 9 digits:

/usr/xpg4/bin/awk  '/^[0-9]{9}/ && !/^[0-9]{10}/' file

Use only /usr/xpg4/bin/awk.

the grep is the utility that you'd better use.
grep '^[0-9]\{4\}$' <filename>

awk 'length==4 && $0+0==$0' file