I have a number of text files that have the same name. Each file is saved in a different folder also each file contains one column of numbers as follow:
FILE.TXT FILE.TXT FILE.TXT FILE.TXT ....
5 4 5 7
8 2 1 5
6 1 1 1
1 3 5 9
3 1 8 9
. . . .
. . . .
. . . .
I want to merge the files in one spreadsheet (CSV format) and I want the names of the columns to be the same as the names of the folders that contain that file. I tried for loop as follow:
#!/bin/bash
in=a/b/c
for i in $(cat $in/folders_names.txt); do # i is the folder name that contain the file.txt
paste ${in}/${i}/file.txt
done > all_files.txt
sed 's/ */,/g' all_files.txt >all_files.csv &
This code is pasting all the columns ( from all the files ) in one column ( in the file all_files.txt). I don't know what I am doing wrong. Any suggestions?
paste {a,b,c}/file.txt
? 2) addall_files.txt
as first argument of paste in your loop ?