1

I have a text file that contains a big matrix, that columns are split like the following example:

     col1 col2 col3
row1  ..   ..   .. 
row2  ..   ..   ..
row3  ..   ..   ..
row4  ..   ..   ..
row5  ..   ..   ..
row6  ..   ..   ..

     col4 col5 col6
row1  ..   ..   .. 
row2  ..   ..   ..
row3  ..   ..   ..
row4  ..   ..   ..
row5  ..   ..   ..
row6  ..   ..   ..

How can I concatenate the splitted columns horizontally so that the file can be something like this:

     col1 col2 col3 col4 col5 col6
row1  ..   ..   ..   ..   ..   .. 
row2  ..   ..   ..   ..   ..   .. 
row3  ..   ..   ..   ..   ..   .. 
row4  ..   ..   ..   ..   ..   .. 
row5  ..   ..   ..   ..   ..   .. 
row6  ..   ..   ..   ..   ..   .. 
3
  • Was "row1 .. row6" and "col1 .. col6" part of file or just imaginary ? – daisy Oct 7 '12 at 5:41
  • Just as an example,so it is imaginary. The actual size is much larger. – xiaohan2012 Oct 7 '12 at 6:17
  • 3
    Why do you need to use vi? It would be easier with tail/head and paste. – mouviciel Oct 7 '12 at 7:15
6

What you want is the “Visual mode blockwise”, see :h ctrl-v. Here the steps to reproduce:

  • move the cursor to the column before col4
  • press Ctrl + V
  • go all the way down: G
  • mark to the end of the columns: $
  • delete the columns: d
  • go to the end of col3: g g $
  • paste the columns: p
0
3
paste FILE1.txt FILE2.txt

I need to know if row1, row2 etcc are values or just to orient? if they are value it should be like:

cut -b 5- FILE2.txt | paste FILE1.txt -

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.