I have the following problem and hope someone could help me.
I have 184 files, each with 5 columns (c1, c2, c3, c4, c5). I am only interrested in column 5, and would like to paste column 5 from all the 184 files into one file. I have tried the following with two files
The above command line does work, but it pastes colum 5 in one column in the new file (a06.txt). I want it to do it side by side, i.e. c5file1 c5file2, instead of c5file1
c5file2
At the end, I expect to have a file with c5file2 c5file2 c5file3....c5file184.
You have posted this request in the incorrect area of the forums. I'll think about the solution and get back to you once a moderator has moved the thread.
This smells like homework, but here is some of the answer. First I would set up a loop to go from 1...184 and dump the awk results to a file say 'result.txt'. Next I would use the paste command to put them in your desired format.
But for the way you have listed the problem here is the answer
awk '{print $5}' file1 ...... file184>result.txt;paste -s a06.txt
These two command lines "awk '{print $5}' file1 ...... file184>result.txt;paste -s result.txt > a06.txt" give the following output:
c5file1
c5file2
.
.
.
c5file184
which was what I had before
The format should be as "c5file2 c5file2 c5file3....c5file184", i.e. I need the columns to be side by side.
Thanks again!
184 is the no. of files. The reason behind the "$(ls -1 file* |sort -n -k1.5)" is to get the files in correct alphabetical order (it skips 'file' and sorts on 1, 2, 3...). If your filenames are not following a regular pattern, then you may need to put them manually in the correct order like this: