0
{gsub(/[ \t]+$/, "", $4); length($4) < 9 || length($4) > 12 } {print $4$1} {print length($4)} { fails4++ }

so I have this portion above that supposed to validate the 4th field thus($4) for if lenght < 9 or if lenght is greater than 11 characters its supposed to fail the validation... even after i print the length i get 11 characters and I set validation to greater than 12 but its still failing

What I am trying to DO is correctly account for the length of the field, if there are any white spaces in $4 field it supposed to trim and get the length and fail if its less that 9 or greater 11 characters

length($4) < 9 || length($4) > 11 {print $4$1} {print length($4)} { fails4++ }

1 Answer 1

1

It sounds like you want:

{gsub(/^[[:space:]]+|[[:space:]]+$/, "", $4); lgth=length($4)} lgth < 9 || lgth > 11{print $4 $1, lgth; fails4++}

If not, post some sample input and expected output.

Sign up to request clarification or add additional context in comments.

2 Comments

IT is exactly what i needed thank you! if you could expand on the gsub briefly for other readers it would be great
The gsub() just removes any white space from the front or back of a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.