我有这样的文件:
- REPORT_100_COMPLETED.csv
- REPORT_100_FAILED.csv
- REPORT_101_COMPLETED.csv
- REPORT_101_FAILED.csv
- REPORT_102_COMPLETED.csv
- REPORT_102_FAILED.csv
我希望根据相关 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
等等,任何人都可以帮忙吗?先感谢您!
答案1
for i in REPORT_*_*.csv ;do
dir=$(cut -d'_' -f2 <<<$i)
mkdir -p $dir && mv $i $dir/
done