0

I have the following output:

Column1
1.2.3.1
1.2.3.2
1.2.3.3
1.2.3.4
1.2.3.5
1.2.3.6
Column2
1.2.3.7
1.2.3.8
1.2.3.9

I would like to split into 2 columns once it reaches Column2.
For example:

Column1      Column2
1.2.3.1      1.2.3.7
1.2.3.2      1.2.3.8
1.2.3.3      1.2.3.9
1.2.3.4
1.2.3.5
1.2.3.6

I've tried "pr -2 -t" but it doesn't know how to split based on the matching criteria.

Any suggestion please?

2 Answers 2

1

Using csplit and paste and two temporary files:

csplit -z file '/^Column/' '{*}' # write output to xx00, xx01
paste xx*
rm xx00 xx01                     # cleanup
1
  • Unfortunately, the csplit command didn't work for me, probably due to the syntax.
    – richtric
    May 27, 2020 at 23:25
0

You could use a regular expression tool to rearrange the blocks into lines

$ cat output | sed -e :a -e '$!N;/\nColumn/{P;D;}' -e 's/\n/ /;ta'
Column1 1.2.3.1 1.2.3.2 1.2.3.3 1.2.3.4 1.2.3.5 1.2.3.6
Column2 1.2.3.7 1.2.3.8 1.2.3.9

and then perform a simple transpose, using the BSD rs command for example

$ cat output | sed -e :a -e '$!N;/\nColumn/{P;D;}' -e 's/\n/ /;ta' | rs -T
Column1  Column2
1.2.3.1  1.2.3.7
1.2.3.2  1.2.3.8
1.2.3.3  1.2.3.9
1.2.3.4  
1.2.3.5  
1.2.3.6  

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .