If the number suffixes of interest are of fixed length and all you care about is filtering out the files that have an additional extension, the following glob (NOT a regex, but a wildcard expression) will do:
ifrontThermal64.[0-9][0-9][0-9][0-9][0-9]
E.g.:
printf "%s\n" ifrontThermal64.[0-9][0-9][0-9][0-9][0-9]
Note that globs always match against the entire filename, whereas grep
performs substring matching by default.
As for why your approach didn't work:
- Your regex isn't quoted, so the shell's parsing 'eats' the
\
, thereby altering it. - Also, whether
grep
recognizes\d
is platform-dependent; to rule out such issues, use[0-9]
instead. - If you use
grep
without-E
, it uses so-called basic regular expressions, which require that the quantifier+
be escaped as\+
; while you could do that, the generally better option is to instead usegrep -E
or to simply invokegrep
asegrep
in order to use extended regexes, which mostly behave like regular expressions in other languages. .
, when intended to be a literal, should be\
-escaped in a regex (which you did in one of your attempts).- The
-1
option ofls
is implied whenls
is not outputting to a terminal. grep
uses substring matching by default, so use-x
to match against the entire input line (alternatively, use the anchors^
and$
) so as to rule out filenames that match the expression but have an additional extension.
Thus, a corrected version of the original command is:
ls | egrep -x 'ifrontThermal64\.[0-9]+'
As an aside: there's no point in enclosing your commands in parentheses; you'll needlessly create subshells (unless they're optimized away, but the point is that they're not needed).