Need help placing row below next to row above

Hi,

I would like to change this :

 kpt#  38, nband= 40, wtk=  1.00000, kpt=  0.8000  0.8000  0.7000 (reduced coord)
 -19.20800 -18.99818  -7.87808  -7.79442  -7.52754  -7.47870  -7.34989  -7.27152
  -6.83504  -6.74311  -6.66652  -6.57237  -5.55966  -5.01640  -4.21031  -4.13873
  -3.33031  -3.01657   2.45129   4.18701   6.15168   6.55283   8.46406   8.61202
   9.90925  12.12516  13.41784  14.80962  17.48936  18.38129  20.03909  20.75073
  21.99101  22.87881  23.89400  24.19821  25.81356  26.49434  26.72360  27.44037

into this

kpt#  38, nband= 40, wtk=  1.00000, kpt=  0.8000  0.8000  0.7000 (reduced coord)
 -19.20800 -18.99818  -7.87808  -7.79442  -7.52754  -7.47870  -7.34989  -7.2715 -6.83504  -6.74311  -6.66652  -6.57237  -5.55966  -5.01640  -4.21031  -4.13873 -3.33031  -3.01657   2.45129   4.18701   6.15168   6.55283   8.46406   8.61202 9.90925  12.12516  13.41784  14.80962  17.48936  18.38129  20.03909  20.75073 21.99101  22.87881  23.89400  24.19821  25.81356  26.49434  26.72360  27.44037

for all kpt#[1-N]. This means 5 strings of values will become a string. I have attached the output file which contains the raw information. I apologize in advance as I've never gotten around to properly explore sed and awk. Any help is deeply appreciated. Thanks.

One way of doing it:

awk '/kpt/{print $0;next}{printf $0}!(NR%6){print ""}' file
1 Like

Many thanks!

With the given input file, ripat's suggestion works fine. But using user supplied data as a format string to printf is risky. If an input line ever happens to contain a % character followed by an alphabetic character (with an optional string of digits before the alphabetic character), you could get very different results.
An alternative way to do this (avoiding this issue) is:

awk 'NR%6<2{print}NR%6>1{printf("%s",$0)}' output.txt