2

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!

0
2
for i in REPORT_*_*.csv ;do
  dir=$(cut -d'_' -f2 <<<$i)
  mkdir -p $dir && mv $i $dir/
done
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.