Laddo wrote: > > Hi all Hello,
> I have a log file which is generated by backup script and i am writing a > perl script to sort the log so as to prepare it to put into mysql > database and iam having a problem in doing that. > > my log file is like this (I have written line numbers for clarity only ) > > 1 INCREMENTAL OF staff ON 2002-08-28 FROM 08/27/02 STARTS AT At > block 315825. > 2 INCREMENTAL OF www.cs <http://www.cs> ON 2002-08-28 FROM > 08/27/02 STARTS AT At block 102860. > 3 INCREMENTAL OF staff_homepages ON 2002-08-28 FROM 08/27/02 > STARTS AT At block 103142. > 4 INCREMENTAL OF ftp.cs <ftp://ftp.cs> ON 2002-08-28 FROM > 08/27/02 STARTS AT At block 103204 > 5 INCREMENTAL OF local ON 2002-08-28 FROM 08/27/02 STARTS AT At > block 103216. > 6 INCREMENTAL OF Hyper-G ON 2002-08-28 FROM 08/27/02 STARTS AT At > block 103236. > 7 INCREMENTAL OF submissions ON 2002-08-28 FROM 08/27/02 STARTS > AT At block 104278. > 8 INCREMENTAL OF src ON 2002-08-28 FROM 08/27/02 STARTS AT At > block 110373. > 9 INCREMENTAL OF IMAP ON 2002-08-28 FROM 08/27/02 STARTS AT At > block 110455. > > i want a script that can give me output like this > > "2002-08-28","$PROBLEM","staff", "315825" > > $PROBLEM is actually tape number which should be derived from > blocknumbers in the logfile e.g say the initial TAPE No =1 and the > script should check if the block number is greater than the block number > in the next line it should replace $PROBLEM with TAPE 1 Other wise > should do something like $PROBLEM=$TAPE +1 > > Like in my example > line 1 should give the output as > > "2002-08-28","TAPE 1","staff", "315825" # because 315825 > 102860 > > line 2 should be > > "2002-08-28", "TAPE 2","www.cs", "102860" # tape=$tape +1 is required > because 102860 ! > 103142 > > > and the same with other lines .... > > i can do it with awk and bash but as iam learning perl iam trying to > write everything in perl. For all the guru's out there i know its very > simple please help > > Hmmm i hope i have explained the concept correctly Here is one way to do it: my $tape = 1; my $start_block = 0; while ( <LOG> ) { next unless /^INCREMENTAL OF\s+(\S+).+?ON\s+([\d-]+).+?block\s+(\d+)/; $tape++ if $3 < $start_block; print '"', join( '","', $2, "TAPE $tape", $1, $3 ), '"'; $start_block = $3; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]