1

Hi,
I have multiple files with the multiple columns, I want to select few different columns from every file and make it to single file. I have read the post

file1

Day   present absent total
Mon    10      1      11 
TUE    11      0      11
WED     9      2      11
THU     8      3      11 
...

file2

Day   present absent total
Mon    18      3      21 
TUE    15      6      21
WED    19      2      21
THU    17      4      21 
....

file 3

Day   present absent total
Mon    50      1      51 
TUE    51      0      51
WED    49      2      51
THU    48      3      51 
....

make it to single file

Day   present present present
Mon    10      18      50 
TUE    11      15      51
WED     9      19      49
THU     8      17      48
 ....

How can I make it with shell/bash command?

[awk '{a\[FNR\] = a\[FNR\]" " $7}END{for(i=0;i<FNR;i++) print a\[i\]}'][2]         
Community
  • 1
  • 1

1 Answers1

1

quick way to do it:

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

if you want the output to be in a "pretty" format, paste 1 2 3|awk -v OFS='\t' '{print...}' or pipe the output to |column -t.

output:

Day  present  present  present
Mon  10       18       50
TUE  11       15       51
WED  9        19       49
THU  8        17       48
Kent
  • 189,393
  • 32
  • 233
  • 301
  • It did n't worked for single file having around 80 columns bcause it conatin zero valus in most of cells ... I sticked to the previous answer ' awk '{a\[FNR\] = a\[FNR\]" " $7}END{for(i=0;i –  Jan 28 '15 at 15:00