-1

I am wondering how one could merge four columns into two in the following manner (using the awk command, or other possible commands).

For example,

Old:

A B C D 
E F G H
I J K L 
M N O P 
.
.
.

New:

A B 
C D 
E F
G H  
I J  
K L  
M N  
O P 
.  
.  

Thanks so much!

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
kwaldner
  • 95
  • 1
  • 6
  • related: https://stackoverflow.com/questions/20608501/print-every-4-columns-to-one-row-in-perl-or-awk – kvantour Nov 27 '18 at 10:26

3 Answers3

2

That's actually quite easy with awk, as per the following transcript:

pax> cat inputFile
A B C D
E F G H

pax> awk '{printf "%s %s\n%s %s\n", $1, $2, $3, $4}' <inputFile
A B
C D
E F
G H
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
2

Hww about using xargs here? Could you please try following once.

xargs -n 2 < Input_file

Output will be as follows.

A B
C D
E F
G H
I J
K L
M N
O P
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
1

with GNU sed

$ sed 's/ /\n/2' file

replace 2nd space with new line.

karakfa
  • 66,216
  • 7
  • 41
  • 56