Help with finding length of a field

I have a pipe delimited file. I need to check that the first and second fields are 5 characters long and if not i need to append 0 in front of them to make them 5 characters long. can some body let mwe know how i can find the length of the two fields and then make them 5 characters long if they are not.

e.g:

it needs to be

One of the ways:

echo "2|251|25G|NY|NY"|awk '{printf("%0.5d|%0.5d|",$1,$2);print $3,$4,$5}' FS='|' OFS='|'

Or this one:

awk 'BEGIN {FS="|"}{printf("%05d|%05d|%s|%s|%s\n",$1,$2,$3,$4,$5)}' file

Regards

can somebody let me know first how i can print the records that doesnt have 5 characters in the 1st and 2nd fields please?

nawk ' length($1) != 5 && length($2) != 5' myFile

vgreshh,

its printing everything even when the first and second fields are 5 characters long. something wrong?

sorry - forgot the field seprator

nawk -F'|' length($1) != 5 || length($2) != 5'

Also yuu probably want to print a records if EITHER one of the fields is not 5 chars long?