Validate ZIP code in Shell-Script

Asked

Viewed 292 times

0

I’m entering this world of regular expressions, I’m having a doubt, I read about metacharacters, etc. Well, I’m trying to validate a zip code and I’m using the following command and I’m not getting it.. i have already replaced d by [0-9] and succeeded, but so am not succeeding:

cat arquivo.txt | grep -E '^\d{5}[-]\d{3}'

In the.txt file you have the line: 02954-852

Grateful.

3 answers

2


Thank you for answering, but the simplest solution was because d is not recognized by the -E parameter but by -P (Perl), the code looked like this:

cat arquivo.txt | grep -P '^\d{5}-\d{3}$'

But thank you very much for your attention.

1

1

You may not have closed the expression with dollar sign: Example:

^\d{5}[-]\d{3}$

Browser other questions tagged

You are not signed in. Login or sign up in order to post.