1753720 Members
5013 Online
108799 Solutions
New Discussion юеВ

Help on perl join

 
SOLVED
Go to solution
Junior C.
Frequent Advisor

Help on perl join

All,

I have text file as follow. I need help in joining three(3) lines.

9/1/2007 0:00
4.00
3.38
9/2/2007 0:00
3.86
2.95
9/3/2007 0:00
3.90
3.18

Following are the result I'm looking for.

9/1/2007 0:00 4.00 3.38
9/2/2007 0:00 3.86 2.95
9/3/2007 0:00 3.90 3.18

Thanks, in advance.

JC
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: Help on perl join

Hi JC:

# cat ./myjoin
#!/usr/bin/perl
use strict;
use warnings;
my $i = 0;
my @line;
while (<>) {
chomp;
$i++;
if ( $i <= 3 ) {
push @line, $_;
}
else {
$i = 1;
print "@line\n";
@line = ();
push @line, $_;
}
}
print "@line\n" if @line;
1;

...run as:

./myjoin file

Regards!

...JRF...
Junior C.
Frequent Advisor

Re: Help on perl join

James,


I appreciate your reply. Thank, for the script.



Thread Close


JC