On Thu, Jan 24, 2002 at 11:59:05PM +1100, Stuart wrote: > Hi > Please help if you can. > Kind Regards > Stuart Clark > > > How do I make the number between the "a" and the "z" take up 10 > positions within the line by adding zero's in front. > The numbers between the "a" and "z" are not always the same length but > they always start at the 24th position in the line. > > # start of file test > 30000034364717283459322a15.32zM 042001H > 30000045434551648534245a243.56zM 040532H > 30000053232540927543293a2.45zM 040332H > # end of file test > > > > open (IN,"test") || die "Could not open the test file\n"; > open (OUT,">result") || die "Error could not create the output > file\n"; > > while (<IN>) { > > s/a.*?z/WHAT GOES HERE?/;
s/a([0-9]+.[0-9])+z/sprintf("8.2%f",$1)/e > > > print OUT $_; > } > > close(IN) || die "Error cannot close test file\n"; > close(OUT) || die "Error cannot close output file\n"; > > > > # output file must look like this > 3000003436471728345932200000015.32M 042001H > 3000004543455164853424500000243.56M 040532H > 3000005323254092754329300000002.45M 040332H > > ---end quoted text--- Try "perldoc -f sprintf", #!/usr/bin/perl open IN,'test' or die "test: $! \n"; open OUT,'>result' or die "result: $!\n"; while (<IN>) { s/a([0-9]+\.?[0-9]+)z/sprintf("%011.2f",$1)/e; print OUT } -- Frank Booth - Consultant Parasol Solutions Limited. (www.parasolsolutions.com) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]