grep command using wildcards [0-9]
Solution 1:
It's not clear from your description whether your expression is failing to match things you want, or matching things you don't want.
If it's the latter, then it may be because .
in a grep regular expression matches any single character (except the newline character - however grep is normally line-based anyway). To match a literal dot (period) you need to escape it \.
or place it in a character set as you have done for the decimal digit ranges:
grep "[.][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"
You also mention that the expression should match data "ending with" - it's not clear whether you mean a line ending or a word boundary - these are respectively $
and \b
(or \>
) ex.
grep "[.][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$"
grep "[.][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\b"
You can also shorten the expression using a quantifier - switching to extended regular expression (ERE) mode1:
grep -E "[.][0-9]{7}$"
1 In GNU grep, you can use quantifiers in basic regular expression (BRE) mode by escaping the braces grep "[.][0-9]\{7\}$"