I'm trying to add columns to a csv file from multiple files. This is what I have tried so far, but keep ending up with either an empty file or just the column from the last file.
while read i; do
awk '{print $4}' ${i}.txt > ${i}_temp
awk 'NR==FNR{a[NR]=$0;next}{print a[FNR],$0}' OFS=, test.csv ${i}_temp >> test.csv
done < file_list
The file list is just a list of accession numbers:
NA123
NA124
NA125
...
The text files that they correspond to have 4 columns in them, and I want to copy the last column and add it as the next column in a csv file. The contents of the files look like this:
NA123.txt:
April-18 10:00 18:00 8
April-19 09:00 19:00 10
April-20 11:00 16:00 5
...
NA124.txt:
April-18 14:00 18:00 4
April-19 09:00 15:00 6
April-20 07:00 16:00 9
...
NA125.txt:
April-18 10:00 22:00 12
April-19 09:00 12:00 3
April-20 06:00 16:00 10
...
test.csv:
0,
1,
2,
...
I would like the output to be:
0,8,4,12
1,10,6,3
2,5,9,10
...
What do I need to change about this or is there a more efficient way to do this?