RE: How to count lines in an output file
-Original Message- From: Tim Lago [mailto:[EMAIL PROTECTED]] Sent: 19 February 2002 14:31 To: [EMAIL PROTECTED] Subject: How to count lines in an output file I've written a really simple script that opens a file, reads for specific line of text and copies the matches to an output file, Here it is: open(INFILE, "rmaccess1.txt"); open(OUTFILE, ">outfile.txt"); print "Enter the name of the Media file to analyze and press Enter: \n"; chomp($realname = ); while() { if(/$realname/) { print OUTFILE; $count++; } } Now, I want to add another line that counts the number of lines that were created in the outfile.txt, any help? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = DISCLAIMER 1. The information contained in this E-mail is confidential. It is intended only for the stated addressee(s) and access to it by any other person is unauthorised. If you are not an addressee, you must not disclose, copy, circulate or in any other way use or rely on the information contained in this E-mail. Such unauthorised use may be unlawful. If you have received this E-mail in error, please inform us immediately and delete it and all copies from your system. 2. The views expressed in this E-mail are those of the author, and do not represent the views of AMT-Sybex Group Ltd., its associates or subsidiaries, unless otherwise expressly indicated. In the avoidance of doubt, the insertion of the name of AMT-Sybex Group Ltd., its associate or subsidiary under the name of the sender may constitute an express indication that the views stated in the Mail are those of the named company. = For more information on the AMT Sybex group visit: http://www.amt-sybex.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to count lines in an output file
open(INFILE, "rmaccess1.txt") or die "Can't open rmaccess1.txt: $!"; open(OUTFILE, ">outfile.txt") or die "Can't create outfile.txt: $!"; # ALWAYS check for errors when opening file handles. It's a good habit to get into. print "Enter name of the Media file to analyse: "; # I'd keep the above on one line. Looks a little neater chomp($realname = ); $counter = 0; # Add this while() { if(/$realname/) { print OUTFILE; $counter++; # And add this } } # And finally do something with the new value of $counter print "$counter lines were saved to the output file\n"; HTH John -Original Message- From: Tim Lago [mailto:[EMAIL PROTECTED]] Sent: 19 February 2002 14:31 To: [EMAIL PROTECTED] Subject: How to count lines in an output file I've written a really simple script that opens a file, reads for specific line of text and copies the matches to an output file, Here it is: open(INFILE, "rmaccess1.txt"); open(OUTFILE, ">outfile.txt"); print "Enter the name of the Media file to analyze and press Enter: \n"; chomp($realname = ); while() { if(/$realname/) { print OUTFILE; } } Now, I want to add another line that counts the number of lines that were created in the outfile.txt, any help? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --Confidentiality--. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to count lines in an output file
See below: On 2/19/02 9:30 AM, "Tim Lago" <[EMAIL PROTECTED]> wrote: > open(INFILE, "rmaccess1.txt"); > open(OUTFILE, ">outfile.txt"); > > print "Enter the name of the Media file to analyze and press Enter: \n"; > > chomp($realname = ); my $count; > while() { > > if(/$realname/) { > print OUTFILE; ++$count; > } > > } > print "Number of lines created in outfile.txt: $count"; - geoff -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to count lines in an output file
You could always try something like this: while() { if(/$realname/) { print OUTFILE; $count++; } } $count should have the number of lines at the end. -Original Message- From: Tim Lago To: [EMAIL PROTECTED] Sent: 2/19/02 6:30 AM Subject: How to count lines in an output file I've written a really simple script that opens a file, reads for specific line of text and copies the matches to an output file, Here it is: open(INFILE, "rmaccess1.txt"); open(OUTFILE, ">outfile.txt"); print "Enter the name of the Media file to analyze and press Enter: \n"; chomp($realname = ); while() { if(/$realname/) { print OUTFILE; } } Now, I want to add another line that counts the number of lines that were created in the outfile.txt, any help? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to count lines in an output file
I guess I should have checked the responses first. Well, I guess if there was any doubt... :) -Original Message- From: Timothy Johnson To: 'Tim Lago '; [EMAIL PROTECTED] Sent: 2/19/02 8:12 AM Subject: RE: How to count lines in an output file You could always try something like this: while() { if(/$realname/) { print OUTFILE; $count++; } } $count should have the number of lines at the end. -Original Message- From: Tim Lago To: [EMAIL PROTECTED] Sent: 2/19/02 6:30 AM Subject: How to count lines in an output file I've written a really simple script that opens a file, reads for specific line of text and copies the matches to an output file, Here it is: open(INFILE, "rmaccess1.txt"); open(OUTFILE, ">outfile.txt"); print "Enter the name of the Media file to analyze and press Enter: \n"; chomp($realname = ); while() { if(/$realname/) { print OUTFILE; } } Now, I want to add another line that counts the number of lines that were created in the outfile.txt, any help? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to count lines in an output file
thanks for everyones help, it worked great. "Tim Lago" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I've written a really simple script that opens a file, reads for specific > line of text and copies the matches to an output file, > > Here it is: > > open(INFILE, "rmaccess1.txt"); > open(OUTFILE, ">outfile.txt"); > > print "Enter the name of the Media file to analyze and press Enter: \n"; > > chomp($realname = ); > > while() { > > if(/$realname/) { > print OUTFILE; >} > > } > > Now, I want to add another line that counts the number of lines that were > created in the outfile.txt, any help? > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]