Celeb Glow
general | March 20, 2026

grep command using wildcards [0-9]

grep ".0000000" data > output

I extract the all numeric data ending with .0000000 in the data text file. When I changed this code using wildcard as follows:

grep ".[0-9][0-9][0-9][0-9][0-9][0-9][0-9]" data > output

The above code is supposed to extract all numeric data ending with any seven digits after the dot, but it does not work as it is supposed to be. How I can modify the above code to extract all numeric data ending with any seven digits after the dot?

4

1 Answer

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\}$"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy