Text editing/manipulation

Hello all.
I need to rearrange a very long text file with the following format.
The number of lines in each block is variable, but is between 1 and 10.

Any hints what command could I use for this?
Thank you.

  SAMPLE      2600
  15    3453  159   3970  486   4327  760   4498
  1215  4638  1620  4707  1927  4882  2280  4967
  2564  5079  2894  5284  3229  5441  3846  5678
  SAMPLE      2800
  23    3446  140   3831  308   4172  526   4374
  853   4568  1177  4638  1716  4746  2321  4963
  2604  5111  2823  5284  3045  5410  3917  5788
  4486  5985  5141  6195

The desired output format is:

2600 15     3453  159   3970  486   4327  760   4498
1215   4638  1620  4707  1927  4882  2280  4967
2564   5079  2894  5284  3229  5441  3846  5678
2800 23     3446  140   3831  308   4172  526   4374
853    4568  1177  4638  1716  4746  2321  4963
2604   5111  2823  5284  3045  5410  3917  5788
4486   5985  5141  6195

Try

awk '{ORS = RS} /SAMPLE/ {sub ($1 FS, ""); ORS = FS} 1' file
1 Like

Thank you for your answer.
The example desired format I inserted earlier is displayed slightly differently to what was intended: the number copied from after the "SAMPLE" expression should be inserted not at the start of the first line, but as a new column, pushing the whole input text block out.

Thank you again.

Try

awk '/SAMPLE/ {printf "%s", $2; next} {$0 = "\t" $0; print}'  file
1 Like