Re: Join lines
- From: Paul Lalli <mritty@xxxxxxxxx>
- Date: Tue, 21 Aug 2007 09:57:02 -0700
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
.
- References:
- Join lines
- From: nickli2000
- Join lines
- Prev by Date: Re: Symrefs
- Next by Date: Re: writing array to file?
- Previous by thread: Join lines
- Next by thread: Re: Join lines
- Index(es):
Relevant Pages
|