Linux file names and file sharing
I have a list of files named:
file000
file001
file002
file003
...
file1100
How can I match all files greater than 800 but less than 1000? I am using linux bash
thank
Edit
Actually my files are named:
ab869.enc
cp936.enc
g122345.enc
x2022.enc
abc8859-14.enc
aax5601.enc
cp936-1.enc
so the first solution doesn't match the correct files :(
How can I match files with numbers between 800-999?
source to share
*[89][0-9][0-9].enc
Uses Bash's "pathname" (aka "globbing") expansion function to match all files ending in 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:
mv *[89][0-9][0-9].enc path/to/destination/
If you wanted it to also match a file named "cp850-1.enc", you would need to change the expression:
*[89][0-9][0-9]*.enc
source to share
This is close to what you want:
$ ls *{800..999}{,-*}.enc
ab869.enc abc8859-14.enc cp936-1.enc cp936.enc
The problem is that you raise what you abc8859-14.enc
don't want. In this case egrep will be your friend:
$ ls *{800..999}{,-*}.enc | egrep '[^0-9][0-9]{3}(|-.*)\.enc'
If you want to move or copy files, you probably want to wrap this expression in a loop for
(in certain circumstances, you can use xargs rather than a for loop).
for file in $(ls *{800..999}{,-*}.enc | egrep '[^0-9][0-9]{3}(|-.*)\.enc')
do
# copy abc859-14.enc to abc859-14.bak
basefile=$(basename $file .enc)
cp $file "$basefile.bak"
done
source to share