I have 45 directories in my drive with naming format Sub1,Sub2..Sub45 each consists of more than 300 text files, all text files in each directory have same naming format
regional_vol_GM1.txt
regional_vol_GM2.txt
regional_vol_GM*.txt
I would like to sort the directories and text files in each directory in sequential order and export the data in each file into csv file,
Following is the script that i have written
eval "dirs=($(ls -v --quoting-style=shell-always))"
for dir in "${dirs[@]}"; do
eval "files=($(
ls -vd --quoting-style=shell-always -- "$dir"/t1/regional_vol*.txt))"
tail -q -n 1 -- "${files[@]}" | paste -sd , -
done > data.csv
Now i would like to remodel my output csv file with file name of text file as row value and directory name as column, since every directory has 300 text files with same naming format, i just need one single row with file name as header and directory name as column in csv file