on Wed, 21 Aug 2002 19:26:35 GMT, [EMAIL PROTECTED]
(Zary Necheva) wrote:
> I have text file that has data in this format:
>
> Name: Tammy Johnson
> Address 1:3803 Grenton Ave.
> City, State: Baltimore, MD
> Zip: 21206
>
> Name: Ann Johnson
> Address 1:38 Park Ave.
> City, State: Baltimore, MD
> Zip: 21206
> I have to convert the data in this format (like a report)
>
> Name Address City,
> State Zip
> Tammy Johnson 3803 Grenton Ave Baltimore, MD
> 21206 Ann Johnson 38 Park Ave
> Baltimore, MD 21206
Try this:
#! perl -w
use strict;
my @fields = ('Name: ', 'Address 1:', 'City, State: ', 'Zip: ');
open IN, "<inputfile" or die "Cannot open input file: $!";
$/ = ''; # set paragraph mode
while (<IN>) {
my @address = ();
for my $f (@fields) {
push @address, (/$f(.*)$/m ? $1 : '***unknown***');
}
print pack("A25" x @fields, @address);
}
close IN;
--
felix
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]