Gathering data in columns from multiple files

Hello world!

I need to gather all the data from different folders and copy it in an one unique text file in columns format.

Let me explain, let�s say "a, b, c" are 3 data files of thousands and thousands lines (in the reality, I have nearly one hundred).
"a, b, c" are located in the folders A, B and C (respectively).

I want to extract "a, b and c" and joined them in the same text file "d".
Whenever I use the function "paste" or "cat" with a for loop, I get a text file like this format :
a
b
c
All the data are written in line. But I would like to get it in such format :
a b c

Is there a way to write directly in such format ?
Or maybe a way to transform from
a
b
c
to
a b c
after writing.

I hope I was clear enough...

Thanks in advance!

Please use code tags as required by forum rules!

No, you weren't. Are those a, b, and c files one column text files, and you want to join them columnwise? Why doesn't paste work for you?
Please post samples of input data and desired output format based on those data.

hi Rudy :slight_smile:

Yes, this a one-column text files with... nearly 30 000 rows for only one text.

Yes, I can use

paste

, like this :

for i in *
do
paste -d " \t " $i/A/a >> finaldata
done

I obtain a big file with all the data but only in one column (I want it to be copied columnwise)

Any idea ?

EDIT : I will try to be clearer.

I have a lot of files from different time steps. For example, my folders look like :

0.001 (This is the folder for the time step t = 0,001s.)
0.002 (This is the folder for the time step t = 0,002s.)
0.003 (This is the folder for the time step t = 0,003s.)
0.004 (This is the folder for the time step t = 0,004s.)
...
1.000 (This is the folder for the time step t = 1,000s.)

In each folder, I have one data text file for every time step. The name of this data text file is always the same for every time step. For example : "pressure".
The data text file "pressure" is given to me like this for the time step

t = 0,001s

:

1.2
2.5
3
7
5.4
0.6
5.4
12
      

For the other time steps, I have a similar text file with different values.

When I try to gather all the data together, I have this kind of output :

1.2
2.5
3
7
5.4
0.6
5.4
12  

data from t = 0,002 s

data from t = 0,003 s

etc...

Now, I want the output to be like :

1.2                                           data from t = 0,002 s                                             data from t = 0,003s                                             etc...
2.5
3
7
5.4
0.6
5.4
12

cat file[123]
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
B1
B2
B3
B4
B5
B6
B7
B8
B9
B10
B11
B12
C1
C2
C3
C4
C5
C6
C7
C8
C9
paste file[123]
A1      B1      C1
A2      B2      C2
A3      B3      C3
A4      B4      C4
A5      B5      C5
A6      B6      C6
A7      B7      C7
A8      B8      C8
A9      B9      C9
A10     B10
        B11
        B12

Thanks RudiC again!

How can I do that for 100 text files ? should I write :

paste file[123456..100]

? I try to figure out how to implement a

For Loop

, but I don�t get the desired output...

Any ideas ? :slight_smile:

How about experimenting, trying and testing/expanding boundaries?

1 Like