Take the following contents of a file:
"52245" "528" "06156903" "52246" "530" "00584709"
What pattern would match both 52245 and 52246 but nothing else?
Take the following contents of a file:
"52245" "528" "06156903" "52246" "530" "00584709"
What pattern would match both 52245 and 52246 but nothing else?
Something that can only match those two numbers and nothing else:
^\"5224[56]\"$
Now if you're looking for something a bit more general (for example, any number with 5 digits), you'll want something like
^\"\d{5}\"$
I'm assuming the quotation marks ("
) are part of the file. If they aren't, omit the \"
parts from the expression.
The particular grep expression you want is this:
grep -E "^\"[[:digit:]]{5}\"$" filename
or to take a suggestion from the comments:
grep -P "^\"\d{5}\"$" filename
I've tested both and they work on my machine!
^"5224[56]"$
^"5224(5|6)"$
^"52{2}4[56]"$
^"(52245|52246)"$
...
You should base the regex you use on the semantic you want to express. If you are looking for two arbitrary numbers use ^"(52245|52246)"$
. If the numbers have any meaning - a type code or something like that - I would stick with ^"5224(5|6)"$
.