Reputation: 3842
For example, there are many files in the same path named like:
FILE-2013-01-02.csv, FILE-2013-01-03.csv,......FILE-2013-12-31.csv
I want to select several files and copy them into other path.
Simply, to select files containing the information for January, I use cp -r FILE-2013-01* ./other/path
.
If I want to select all the files in Month 1, 3, 5, 7 with one sentence in shell, what should I do?
Upvotes: 0
Views: 145
Reputation: 674
cp -r FILE-2013-0[1357]-[0-3][0-9].csv /otherpath/
If you want to mach 2013-11 and 2013-02 but no 2013-12 or 2013-01 you could use grep -E -w to get more complex regexp options: 2013-(1[01]|0[2357])
ls | grep -E -w '^FILE-2013-(1[01]|0[2357])-[0-3][0-9].csv$' | xargs -i cp {} /otherpath/
I prefer find to achieve this.
find ./ -type f -name "FILE-2013-0[1357]-[0-3][0-9].csv" -exec cp -r {} /otherpath/ \;
Upvotes: 0