Skip to main content
improved code formatting
Source Link
Inian
  • 13.1k
  • 2
  • 42
  • 55

Merge Multiplemultiple columns based based on the first column 1 UNIX loopvalues

I have multiple files (10+) that I want to merge/join into the one output file, for example:

file 1

2000 0.0202094
2001 0.0225532
2002 0.02553
2003 0.0261099
2004 0.0280311
2005 0.028843

file 2

2000 0.0343179
2001 0.036318
2003 0.039579
2004 0.0412106
2005 0.041264

file 3

2004 0.068689
2005 0.0645474

All files have the same two columns are are of unequal length.

The desired output would be:

        file1       file2      file3
2000    0.0202094   0.0343179
2001    0.0225532   0.036318
2002    0.02553
2003    0.0261099   0.0395799
2004    0.0280311   0.0412106   0.0686893
2005    0.028843    0.041264    0.0645474

I have tried the following code however the values don't align with the first column:

awk '{printf($1); for(i=2;i<=NF;i+=2) printf ("\t%s", $i); printf "\n"}' <(paste file*) > mergedfile.txt

Thanks

awk '{printf($1); for(i=2;i<=NF;i+=2) printf ("\t%s", $i); printf "\n"}' <(paste file*) > mergedfile.txt

Merge Multiple columns based based on column 1 UNIX loop

I have multiple files (10+) that I want to merge/join into the one output file, for example:

file 1

2000 0.0202094
2001 0.0225532
2002 0.02553
2003 0.0261099
2004 0.0280311
2005 0.028843

file 2

2000 0.0343179
2001 0.036318
2003 0.039579
2004 0.0412106
2005 0.041264

file 3

2004 0.068689
2005 0.0645474

All files have the same two columns are are of unequal length.

The desired output would be:

        file1       file2      file3
2000    0.0202094   0.0343179
2001    0.0225532   0.036318
2002    0.02553
2003    0.0261099   0.0395799
2004    0.0280311   0.0412106   0.0686893
2005    0.028843    0.041264    0.0645474

I have tried the following code however the values don't align with the first column:

awk '{printf($1); for(i=2;i<=NF;i+=2) printf ("\t%s", $i); printf "\n"}' <(paste file*) > mergedfile.txt

Thanks

Merge multiple columns based on the first column values

I have multiple files (10+) that I want to merge/join into the one output file, for example:

file 1

2000 0.0202094
2001 0.0225532
2002 0.02553
2003 0.0261099
2004 0.0280311
2005 0.028843

file 2

2000 0.0343179
2001 0.036318
2003 0.039579
2004 0.0412106
2005 0.041264

file 3

2004 0.068689
2005 0.0645474

All files have the same two columns are are of unequal length.

The desired output would be:

        file1       file2      file3
2000    0.0202094   0.0343179
2001    0.0225532   0.036318
2002    0.02553
2003    0.0261099   0.0395799
2004    0.0280311   0.0412106   0.0686893
2005    0.028843    0.041264    0.0645474

I have tried the following code however the values don't align with the first column:

awk '{printf($1); for(i=2;i<=NF;i+=2) printf ("\t%s", $i); printf "\n"}' <(paste file*) > mergedfile.txt
added 303 characters in body
Source Link

I have multiple files (10+) that I want to merge/join into the one output file, for example:

file 1

enter image description here

2000 0.0202094
2001 0.0225532
2002 0.02553
2003 0.0261099
2004 0.0280311
2005 0.028843

file 2

enter image description here

2000 0.0343179
2001 0.036318
2003 0.039579
2004 0.0412106
2005 0.041264

file 3

enter image description here

2004 0.068689
2005 0.0645474

All files have the same two columns are are of unequal length.

The desired output would be:

        file1       file2      file3
2000    0.0202094   0.0343179
2001    0.0225532   0.036318
2002    0.02553
2003    0.0261099   0.0395799
2004    0.0280311   0.0412106   0.0686893
2005    0.028843    0.041264    0.0645474

enter image description here I have tried the following code however the values don't align with the first column:

awk '{printf($1); for(i=2;i<=NF;i+=2) printf ("\t%s", $i); printf "\n"}' <(paste file*) > mergedfile.txt

Thanks

I have multiple files (10+) that I want to merge/join into the one output file, for example:

file 1

enter image description here

file 2

enter image description here

file 3

enter image description here

All files have the same two columns are are of unequal length.

The desired output would be:

enter image description here

Thanks

I have multiple files (10+) that I want to merge/join into the one output file, for example:

file 1

2000 0.0202094
2001 0.0225532
2002 0.02553
2003 0.0261099
2004 0.0280311
2005 0.028843

file 2

2000 0.0343179
2001 0.036318
2003 0.039579
2004 0.0412106
2005 0.041264

file 3

2004 0.068689
2005 0.0645474

All files have the same two columns are are of unequal length.

The desired output would be:

        file1       file2      file3
2000    0.0202094   0.0343179
2001    0.0225532   0.036318
2002    0.02553
2003    0.0261099   0.0395799
2004    0.0280311   0.0412106   0.0686893
2005    0.028843    0.041264    0.0645474

I have tried the following code however the values don't align with the first column:

awk '{printf($1); for(i=2;i<=NF;i+=2) printf ("\t%s", $i); printf "\n"}' <(paste file*) > mergedfile.txt

Thanks

Source Link

Merge Multiple columns based based on column 1 UNIX loop

I have multiple files (10+) that I want to merge/join into the one output file, for example:

file 1

enter image description here

file 2

enter image description here

file 3

enter image description here

All files have the same two columns are are of unequal length.

The desired output would be:

enter image description here

Thanks