Since you tagged bash, you can actually do this with the shell's filename matching, using extended globs:
$ shopt -s extglob
$ touch /some/path/{2.6.0.3-8,22.66.0.333-8,foobar}
$ printf "%s\n" /some/path/+([0-9]).+([0-9]).+([0-9]).+([0-9])-+([0-9])
/some/path/22.66.0.333-8
/some/path/2.6.0.3-8
The pattern there works like more common things like *
or *.png
, so you can just stick the fixed parts like paths in it. Add a trailing slash /
to only match directories. (the slash does appear in the output too, though.)
In ERE regex, the pattern is the same as [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+-[0-9]+
. A fuzzier version would just check for the allowed characters, like +([-.0-9])
(or [-.0-9]+
in ERE), but that of course would also match e.g. 123..456
.
If you want to just print the filenames, find
might be easier, but if you want to run a command on them, then a shell loop is also an option (along with find -exec
).
find
with either a-name
or-regex
predicate (or the case-insensitive-iname
and-iregex
). – cas Jan 22 '18 at 09:59x.x.x.x-x
canx
be more than one digit? – Sundeep Jan 22 '18 at 11:08