0

This question already has an answer here:

I have this command:

for file in file??.txt; do awk -f vypis_z_dcout.awk "$file" > "$file".csv; done

The result is a column of numbers from each file and I want to connect results from all files in one file like its columns. How to add to this command?

paste <(cat f.csv) <(cat f1.csv) <(cat f2.csv) <(cat f3.csv) <(cat f4.csv) .... insert "$file".csv ... > out.csv

Or how to get a file where in the first column will be file01.csv, in the second file02.csv and so on? Thank you

marked as duplicate by αғsнιη, Prvt_Yadv, Fabby, Michael Homer, Rui F Ribeiro Apr 29 at 9:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

If I understand what you're saying, you start out with a set of files with names along the lines of:

file01.txt
file02.txt
file03.txt

You then process each one of those text files in turn with awk, which produces a column of data for each file processed. So in this hypothetical directory, there are now 6 files:

file01.txt
file02.txt
file03.txt
file01.txt.csv
file02.txt.csv
file03.txt.csv

And the last 3 files are the results of the awk program.

To paste the CSV files produced in the previous step together into one CSV file with as many columns as there are files generated in the previous step, use:

paste -d '[DELIMITER]' file??.txt.csv > out.csv

Replace [DELIMITER] in the above code with the character you want to use as the delimiter in the resulting CSV file. For example, if file01.txt.csv contained the following data:

1
2
3

...and file02.txt.csv contained the following data:

4
5
6

...and file03.txt.csv contained the following data:

7
8
9

...then paste -d ';' file??.txt.csv > out.csv would fill the file "out.csv" with:

1;4;7
2;5;8
3;6;9

Not the answer you're looking for? Browse other questions tagged or ask your own question.