Sudarsan Raghavan wrote: > > > > > > > > I need to do something, but being new to Perl I'm not sure it's possible > > or how to do it. I need to remove lines of information from a text file > > based on information in another file. The first file contains information > > about some business transactions, each line describing one transaction. The > > second file is a log file reporting errors occurred during some processing > > done on the first file. The log file identifies each transaction that > > failed by its line number in the transaction file. The following is a sample > > of information in each file > > > > > > ---------- sample log file data ---------- > > > Line no: 1, Field no 5: , Field name: Amount > > > Contents: "L8G 4A7" > > > Error: Only digits and one point allowed > > > ------------------------------------------------ > > > Sample transaction file data: > > > > > > "C1","MA00000000000025610","4111111111111111",...etc. > > > ------------------------------------------------------------ > > > > > > I think I need to extract the line number from log file and use it like an > > index to the transaction file. I've already done the first part (extract the > > number) > > A good option is to form a hash with the numbers as the hash keys > For e.g. if the error log file reports the lines 1, 3, 23, 32 to have failed > form a hash with keys 1, 3, 23, 32 and assign them a true value. > > > but don't know how to proceed from there. > > Loop through the transaction file > open (TRANSFILE, $your_transaction_file_name) or > die "open failed on transaction file : $!\n"; > open (TMPTRANSFILE, "> temp_trans.txt") or > die "open failed in write mode for temp_trans.txt : $!\n"; > while (<TRANSFILE>) { > # $. will contain the current line being processed (perldoc perlvar)
Sorry, that should be $. contains the current line number being processed > > print TMPTRANSFILE unless ($err_line_nums{$.}) > #err_line_nums is the hash with the error line numbers as keys > } > close (TRANSFILE); > close (TMPTRANSFILE); > rename ($your_transaction_file_ name, "$your_transaction_file_name.old"); > #Backup your original file, unlink it if you don't want to > rename ("temp_trans.txt", $your_transaction_file_name); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]