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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cat <filename> |wc -l

Status
Not open for further replies.

vuakhobo

Technical User
Apr 22, 2004
41
US
I have huge file, a smallest one is about 9GIG of data that needs to verify how many records in the files after sftp from the client. Currently I use cat <filename> |wc -l to get the job done. I was wondering is there a better of doing it.
 
wc -l /path/to/filename

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
At the risk of angering the OOUC police, this is one place where [tt]cat[/tt] adds functionality. The [tt]wc[/tt] command on it's own also displays the file name. If all you need is the count, putting it through a pipe with [tt]cat[/tt] does it nicely.

If you just need the count with no file name after it, this works too...
Code:
wc -l < /path/to/filename


 
UUOC Police: so cat isn't needed and doesn't add functionality...

p5
 
sed -n '$=' /path/to/filename

Please let me know if the information that was provided is helpfull.
Edwin Plat
A.K.A. Europe
 
europe
Whilst I agree that your sed solution provides the correct answer the problem is counting the lines in a file. This is what wc was designed to do. I still see wc as the right tool for the job and Sam's suggestion removes the need for cat which keeps the UUOC police happy.



On the internet no one knows you're a dog

Columb Healy
 
What's the OOUC-police?
Being a major of the gtlt-police, I have to add:
It is forbidden to decorate your filename in a fancy, personal gt/lt-style like this:
Code:
cat <filename> | wc -l
because < and > are used all the time on unix.
Code:
cat FILE | wc -l
is perfectly sufficient.


don't visit my homepage:
 
The "OOUC Police" is an organisation created from thin air the moment I typoed "UUOC". [bigsmile]

And while...
Code:
cat <filename> | wc -l
...is incorrect, the line...
Code:
cat <filename | wc -l
...works perfectly well.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top