문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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

LINES=`wc -l file.txt`
echo $LINES
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top