Question

I have a rather large text file (~45MB) and I want to know how many lines total it has. Since the file is so large, it takes too long to open with a text editor and check manually that way. I am wondering if there is a shell command/shell script (I'd prefer a tcsh answer since that's what I use) or any other way to "quickly" (meaning, more quickly than opening the file and checking out the end) determine how many lines the text file has?

I am in a *nix environment.

Était-ce utile?

La solution

wc -l filename

It won't be fast, since it has to read the entire file to count the lines. But there's no other way, since Unix doesn't keep track of that anywhere.

Autres conseils

Use wc (word count, which has a "lines" mode):

LINES=`wc -l file.txt`
echo $LINES
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top