Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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  ..   ..   ..   ..   ..   .. 
share|improve this question
    
Was "row1 .. row6" and "col1 .. col6" part of file or just imaginary ? –  warl0ck 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
add comment

2 Answers 2

up vote 5 down vote accepted

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
share|improve this answer
    
Thanks, it works! –  xiaohan2012 Oct 8 '12 at 4:23
add comment
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 -
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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