Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to count lines in a file

Status
Not open for further replies.

ttlhr

Technical User
Jan 13, 2010
7
US
Hello, i am new to perl. I am trying to understand how to count lines in a file, the most simplest way? Any pointers can help me understand the concept. Please know that i am very new to this so any advanced information would pass over my head.

Thank you

TT
 
hi - does this example you gave, does it go like this:

perl -ne 'END{print$.}' /input/"file location" ?

also, once i get the count, how do i store it somewhere? because further down the script i have to compare it.

thanks again!
 
Do you think this is correct?

open(FILE, "< $file") or die "can't open file: $!";
$count++ while <FILE>;
# $count contains the number of lines
 
if you on unix, wc -l /path/to/file :)


Travis

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top