Search code examples
awkcarriage-return

How to print columns from different files?


I have problem that numbers from different files are not in one line.

I tried:

 paste file1 file2 file3|awk '{print $1, $2, $6, $10}'

file1:

a b c

file2:

d e f

file3:

g h i

output is:

a b
e
h

Desired output:

a b e h

it is columns 1 2 from file1, column 2 from file2 and column 2 from file3


Solution

  • I suggest first to fix end of line in your files:

    dos2unix file1 file2 file3