How can I move all files matching a pattern into a new folder?
I have files like these :
- REPORT_100_COMPLETED.csv
- REPORT_100_FAILED.csv
- REPORT_101_COMPLETED.csv
- REPORT_101_FAILED.csv
- REPORT_102_COMPLETED.csv
- REPORT_102_FAILED.csv
I want all of them to be put inside subfolder according to the related id :
100
| REPORT_100_COMPLETED.csv
| REPORT_100_FAILED.csv
101
| REPORT_101_COMPLETED.csv
| REPORT_101_FAILED.csv
102
| REPORT_102_COMPLETED.csv
| REPORT_102_FAILED.csv
and so on, anyone can help? Thank you in advance!
for i in REPORT_*_*.csv ;do dir=$(cut -d'_' -f2 <<<$i) mkdir -p $dir && mv $i $dir/ done