On 2012-12-14 14:54, samuel desseaux wrote:

=995  \\$xPR$wLivre
=995 \\$bECAM$cECAM
=995  \\$n
=995  \\$oDisponible
=995  \\$kG1 42171

and i want in one line

=995 \\$bECAM$cECAM$kG1 42171$n$oDisponible$xPR$wLivre

echo -n '1   a
1  b
1 c
2  x
=995  \\$xPR$wLivre
=995 \\$bECAM$cECAM
=995  \\$n
=995  \\$oDisponible
=995  \\$kG1 42171
zz 1
zz  2
zz   3
' |perl -Mstrict -wle '
  my ($key, $value);
  while ( my $line = <> ) {
    chomp $line;
    my ($k, $v) = split " ", $line, 2;
    if ( defined $key and $key eq $k ) {
      $value .= $v;
    } else {
      print "$key\t$value" if defined $key;
      ($key, $value) = ($k, $v);
    }
  }
  print "$key\t$value" if defined $key;
'
1       abc
2       x
=995    \\$xPR$wLivre\\$bECAM$cECAM\\$n\\$oDisponible\\$kG1 42171
zz      123

--
Ruud


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to