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 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -