Sed: how to merge two lines moving matched pattern to end of previous line

hello everyone,
im new here, and also programming with awk, sed and grep commands on linux.
In my text i have many lines with this config:

1  1  4  3  1  1  2  5
2  2  1  1  1  3  1  2
1  3  1  1  1  2  2  2
            5  2  4  1
3  2  1  1  4  1  2  1
1  1  3  2  1  1  5  4
1  3  1  1  1  3  3  1
            1  2  2  5
1  2  3  1  5  4  1  1

I wanna move the numbres (separated by 2 spaces) in a line after 12 consecutive spaces to the end of the previous line, resulting in the following:

1  1  4  3  1  1  2  5
2  2  1  1  1  3  1  2
1  3  1  1  1  2  2  2  5  2  4  1
3  2  1  1  4  1  2  1
1  1  3  2  1  1  5  4
1  3  1  1  1  3  3  1  1  2  2  5
1  2  3  1  5  4  1  1

Can you please help?

Thanks in advance for your help!

Julien

Here's a pe(a)rl :wink:

perl -lne 'chomp;if($.==1){$p=$_;next}; if($_=~/^\s+(.*)$/){$p = $p." ".$1}else{print $p; $p=$_} END{print $p}' file
1 Like

It works! many thanks

The thread title asks for a sed solution. Here is one:

sed '
/^    /{H;x;s/\n    */  /;$p;x;d;}
x
1d
${p;x;}
' file
1 Like