I have a list of files named:
file000
file001
file002
file003
...
file1100
How can I match all files that have a number greater than 800 but less than 1000 ? I am using linux bash
Thank you
Edit
Actually, my files are named like:
ab869.enc
cp936.enc
g122345.enc
x2022.enc
abc8859-14.enc
aax5601.enc
cp936-1.enc
so the first solution dont match the correct files :(
How can I match files that have number between 800-999 ?
This is close to what you want:
The trouble is that you're picking up
abc8859-14.enc
, which you don't want. In this case, egrep will be your friend:If you want to move or copy files, you'll probably want to wrap this expression in a
for
loop (in certain circumstances, you might be able to use xargs rather than a for loop).That uses Bash's "pathname expansion" feature (aka "globbing") to match all files ending with a number between 800 and 999 followed by ".enc". (This is not a regular expression).
For example, using the above expression you can do this in your script:
If you need it to also match a file named like "cp850-1.enc", then you would need to change the expression to:
This provides an interesting expansion but can not be tested without the original files in a directory.
There should be an asterisk after both sets of brackets.
Take your pick.
In shell, try this:
This will list the files starting with
file801
and ending withfile999
.For explanation, see the manual: