0

I have 3 files

file1:

compute-0-44
compute-0-2 
compute-0-7 
compute-0-8 

file2:

0
11/29/2017 | 02:01:34
0
05/16/2018 | 08:47:56

file3:

0
963
0
459

When I do paste file1 file2 file 3, I get :

compute-0-44    0       0
compute-0-2     11/29/2017 | 02:01:34   963
compute-0-7     0       0
compute-0-8     05/16/2018 | 08:47:56   459

What I want is :

compute-0-44    0                       0
compute-0-2     11/29/2017 | 02:01:34   963
compute-0-7     0                       0 
compute-0-8     05/16/2018 | 08:47:56   459

Is it possible using paste? If there are any other alternatives like sed, that will serve the purpose too.

choroba
  • 47,233

2 Answers2

1

Using the pr command:

$ pr -mT file{1..3} | expand
compute-0-44            0                       0
compute-0-2             11/29/2017 | 02:01:34   963
compute-0-7             0                       0
compute-0-8             05/16/2018 | 08:47:56   459

From man pr:

   -m, --merge
          print all files in parallel, one in each column, truncate lines,
          but join lines of full length with -J

The pipe through expand converts tabs to spaces - depending on your application, you may not need that (I really only added it here to make the output look correctly formatted on this site).

steeldriver
  • 81,074
0

You can use sed to replace the second tab by 3 tabs if the line doesn't contain a vertical bar:

paste file{1..3} | sed '/|/!s/\t/\t\t\t/2'
choroba
  • 47,233