I have a 50 directories named as Subj1, Subj2 .. Subj50 each containing 152 text files each named in following naming format
regional_vol_GM_atlas1.txt
..
..
regional_vol_GM_atlas152.txt
each file has data arranged in 4 rows and 2 columns, where column values are separated by space delimiter
667869 667869
580083 580083
316133 316133
9020 9020
I would like to export fourth row of each txt file with header into csv file for all 50 directories that i have
I have written a script which exports the data from each text file along with header and creates a CSV but the script takes in all the data inside the text file and pastes in CSV instead of 4th row.
#!/bin/bash
# pasting the file name as column name,
for x in regional_vol_*.txt ; do
sed -i "1s/^/${x}\n/" ${x}
done
# Sorting the files and Subj1 directory name is file name of csv file
paste -d, $(ls -1v regional_vol*.txt ) >> subj1.csv
The figure below describes the output of the file.Subj1 is a directory name

Sub1, Sub2 .. Sub50..right? and each csv of the directory would have only header+4th row of each file .. right? - riteshtch