How to extract one column from multiple files and paste them columwise into a new file

358 views Asked by At

The input filenames look like this: 1012232U1_000n_1012232U1.TXT with n=1...n and contain five colums separated by diffrerent delimeters

200,00; 441,080; 353,651; 404,764;212,94154 201,00; 413,333; 402,073; 422,487;55,48304 202,00; 449,286; 347,365; 413,185;142,21558 203,00; 432,591; 387,947; 397,659;88,41888 204,00; 424,122; 363,040; 401,541;146,12162 205,00; 441,245; 380,924; 417,946;159,18871 206,00; 425,077; 350,233; 415,756;124,92821 207,00; 442,539; 376,096; 418,468;129,83518

I want to extract the last column of every file and paste them into a new file columwise and not appended. It should look like this:

`212,94154;201,61297;...
55,48304;34,53536;...
...;...;...`

I tried $ cut -c39-48 1012232U1_{0001..0096}_1012232U1.TXT | paste -d';' > combinedoutput.txt - for my 96 files but there appears to be something wrong with the cut input as no matter how I specify paste it always appends all fith colum input in one column in the output file. Any ideas?

1

There are 1 answers

1
Norman On

You need to extract all last columns first, so that paste can join them correctly.
Try this:

# Extract last columns into temp files.
for f in 1012232U1_{0001..0096}_1012232U1.TXT ; do
    cut -c39-48 "$f" > "$f.tmp"
done
# Join temp files.
paste -d';' 1012232U1_{0001..0096}_1012232U1.TXT.tmp > combinedoutput.txt