#!/usr/bin/perl
use Modern::Perl '2011';
use autodie;
my @a;
while( <> ) {
chomp;
my @temp if /^start$/;
if( /^end$/ ) {
push @a, [ @temp ];
} else {
push @temp, $_;
}
}
for my $name ( @a ) {
say join ", ", @$name;
}
On Fri, Jul 12, 2013 at 8:39 PM, John W. Krahn <[email protected]> wrote:
> Dr.Ruud wrote:
>
>> On 12/07/2013 13:44, Agnello George wrote:
>>
>>> hi
>>>
>>>
>>> i have raw data that is like this in a flat file .
>>>
>>> start
>>> name:agnello
>>> dob:2 april
>>> address:123 street
>>> end
>>> start
>>> name:babit
>>> dob:13 april
>>> address:3 street
>>> end
>>> start
>>> name:ganesh
>>> dob:1 april
>>> address:23 street
>>> end
>>>
>>>
>>> i need to get the data in the following format
>>>
>>> name:agnello, dob:23 april ,address:123 street
>>> name:babit,dob:13 april,address:3 street
>>> name:ganesh,dob:1 april,address:23 street
>>>
>>
>> perl -0 -wple 's/^start\n(.*?)\nend\n/$_=$1;**y{\n}{ };"$_\n"/emgs'
>>
>
> That should probably be:
>
> perl -0777ple's/^start\n(.*?)\nend/**($x=$1)=~y{\n}{,};$x/emgs'
>
>
>
>
>
> John
> --
> Any intelligent fool can make things bigger and
> more complex... It takes a touch of genius -
> and a lot of courage to move in the opposite
> direction. -- Albert Einstein
>
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>