Re: Join lines



On Aug 21, 12:45 pm, nickli2...@xxxxxxxxx wrote:
I have a file with a lot of lines with a singer number like the
following:

111
222
333
444
555
6666
77777
888
9999
..........

How could I join 3 lines at a time and with a "," in between and at
the beginning of the next line, as in the following:

111,222,333
,444,555,6666
,77777,888,9999
.........

$ cat clpm.pl
#!/opt2/perl/bin/perl
use strict;
use warnings;

while (my $line = <DATA>) {
chomp $line;
print $line;
print "\n" if $. % 3 == 0;
print ",";
}

print "\n";

__DATA__
111
222
333
444
555
6666
77777
888
9999

$ ./clpm.pl
111,222,333
,444,555,6666
,77777,888,9999
,

$

Paul Lalli

.



Relevant Pages