bash - Folder restructure script -
i have directory has .txt,.csv,*.xml files.
original folder structure : /servicer/*.txt,*.csv,*.xml
the file naming convention below :
1. 6573547_billing_582524_1_00001.csv 2. 6573547_billing_582524_1_00001.txt 3. 6573547_billing_582524_1_00001.xml 4. 6573547_billing_582524_1_00002.csv 5. 6573547_billing_582524_1_00002.txt 6. 6573547_billing_582524_1_00002.xml 7. 6573545_billing_582524_1_00002.xml 8. 6573545_billing_582524_1_00002.csv
my requirement create folder structure below , have files inside subfolders.
required folder structure :
/servicer/6573547/582524_1/*.txt,*.csv,*.xml /servicer/6573545/582524_1/*.txt,*.csv,*.xml
the script should executable in windows linux environment.
you can use script in bash:
shopt -s extglob shopt -s nullglob f in *.@(csv|xml|txt); ifs=_ read -ra arr <<< "$f" p="/servicer/${arr[0]}/${arr[2]}_${arr[3]}" mkdir -p "$p" mv "$f" "$p/" done