Aditi Gupta wrote:

On 6/23/05, John W. Krahn <[EMAIL PROTECTED]> wrote:

Aditi Gupta wrote:

I have a file as follows:

#block1
aaa
aaa

#block2
bbb
bbb

#block3
ccc
ccc

and i want to append(or i should say merge) these blocks and get a file like this:

aaabbbccc
aaabbbccc

how can this be done using perl?
please help..


$ echo "
aaa
aaa

bbb
bbb

ccc
ccc
" | perl -l -00ne'my $i; $x[ $i++ ] .= $_ for split /\n/ }{ print for @x'
aaabbbccc
aaabbbccc

I didn't understood the " | perl -l -00 " part.. please explain what is means..

That is short for:

#!/usr/bin/perl -w
use strict;

$/ = '';  # set paragraph mode - switch -00

my @data;
while ( <> ) {
    my $i;
    for my $line ( split /\n/ ) {
        $data[ $i++ ] .= $line;
        }
    }

for my $line ( @data ) {
    print "$line\n";
    }

__END__



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to