Forums »
  Linux Forums And Topics Discussions For Wallpaper Websites Running On Linux Servers »
    How To Count The Number Of Lines In A File In Linux Shell Command

How To Count The Number Of Lines In A File In Linux Shell Command

Description: How To Count The Number Of Lines In A File In Linux Shell Command
Tags: how ,to ,count ,the ,number ,of ,lines ,in ,a ,file ,in ,linux ,shell ,command
Posted On Sun Feb 25, 2007 By tomas In Linux Forums And Topics Discussions For Wallpaper Websites Running On Linux Servers Forums
ok, you have a file and you want to know how many lines it has right?

if you are like me, sometimes we need to know this infromation for some reason or another. well today you are in luck because you've found a cool little tutorial i wrote just to show people like you and me who are learning linux how to send or used linux shell command.

ok the command you need to use is wc

for example, if i have a file called my_text.txt and i want to know how many lines this file has, all if would have to do is send this command:

wc -l my_text.txt


COUNTING ONLY LINES
Like mos UNIX commands, the wc command offers options that instruc the wc to run in different ways, you can tell wc to limit the count just lines, words or characters or any combination of each.

did this short tutorial helped you?


Ademola Fri Apr 27, 2012
Thanks for this quick info. Life saver for a custom ruby code relying on Unix shell to paginate.
Venkat Wed Feb 29, 2012
--------------- text file. Click on Edit>Go To. Give a huge number than expected number of lines. say if you expect to have 2000 lines, give 5000 or just give 200000. It gives an eror "The Line number is beyond the total number of lines" and shows up the the immediately available line. If you have 2379 lines it gives 2380. So whatever it shows up minus 1 is the actual number of lines in the text file. Cheers!!
Omar Wed Feb 08, 2012
Thank you. Is really helpme
Scott Thu Jan 19, 2012
The easy way to get rid of the filename:

$wc -l < file.txt
Ahmed Thu Dec 15, 2011
Some one said they don't see as difficult. Selfish. There was a day you knew nothing about this. Thanks to the Author of this tutorial. I am Java developer, using linux all the time, and I rely these kind of tutorials for quick answer. thanks again
Raewe Tue Dec 13, 2011
Thanks a lot. Very helpful.
Mikey Tue Nov 29, 2011
What about using wc -l with grep where you want to count the number of lines that start with a specific pattern...?
motherfucker Mon Oct 31, 2011
LOVEIN AWESOME MAN!
A.E.S Thu Oct 20, 2011
Thanks! Very useful!!!
C.C Tue Sep 20, 2011
you can get rid of the file name also using cut:
wc -l myfile |cut -d' ' -f1
achacon Wed Sep 07, 2011
form me It's very nice to find very fast, how I can count the numbers of lines in file from linux. Thank you very much!
lala Fri Jul 01, 2011
I'm actually not seeing this as difficult..
Tomas Fri Apr 29, 2011
you can also use grep...

grep -c "" file

Rui Fri Apr 29, 2011
Another cool way to do this without the filename and without having to use awk is to do : cat filename.txt | wc -l
Ling Tue Aug 14, 2012
Yes, this is really cool!
dude Mon Apr 25, 2011
thanks aus! this should really be an OPTION OF wc rather than having to fiddle around the problem.

you saved people's days
Aus Sat Apr 09, 2011
Great thanks !
the results alway come back with file name, eg:
$wc -l text.txt
10 text.txt

I have to get rid of the file name.
$wc -l text.txt | awk -F" " '{ print $1 }'
Michael Thu Nov 22, 2012
Examples that strip additional spaces off:
wc -l text.txt | awk '{print $1}'
or
echo `wc -l < text.txt`
or
awk 'END {print NR}' text.txt
or
sed -n '$=' text.txt
or, not counting empty lines:
grep -c . text.txt
Cori Fri Apr 01, 2011
YES!!!! Thanks
Mezeter Thu Mar 24, 2011
Thank uu very much.
Very usefull.
Thx again.
Arun Fri Mar 11, 2011
what is the shell script for find the lines numbers of a text file are having
words which are 5 to 10 characters long and having first letter as a capital letter
pooja Thu Mar 03, 2011
how can we count the number of lines charachter and number of vowels in a given paragraph
Ishan Sun Feb 27, 2011
Very useful
Thanks!
Tom Sat Feb 12, 2011
Yes. Thanks
John Wed Feb 02, 2011
Perfect, thanks!
ndlinh Fri Jan 21, 2011
Thanks a lot. Very helpful.
WeatherARC Wed Jan 19, 2011
Thanks for this information, just what I needed for the last step in my code, well second to last step.
MarieWithHugeKnockers Fri Jan 14, 2011
Exactly the information I was hoping for!
Igor Wed Dec 29, 2010
Great, very helpful
garved Thu Dec 16, 2010
how can we find the line number of each c programme in linux
Paul Tue Dec 07, 2010
Thank you very much. Very helpful. God bless you!
James Sun Sep 12, 2010
Thanks very much - thought I'd need some sort of script but obviously not!
jonathan Wed Jul 28, 2010
Thanks a lot, saved me writing a shell script...
rajiv Sun Jul 04, 2010
Hi

thanks. I used the command and i just want to make things sure

the command is wc -l l as in London

first i used wc -1 i thought it is number 1 .....


cheers
omsacras Thu Jun 17, 2010
Thanks for the useful tip!

It was just the thing for which I was searching.
nice Thu May 13, 2010
It works very nice many thanks! And i have to had more because my comment is to short!!!
beparas Wed May 12, 2010
Thank you very much
Thank you very much
Thank you very much
Thank you very much
Information
Title: How To Count The Number Of Lines In A File In Linux Shell Command
Info: This Post Has Been Viewed 0 Times Since
Date: Sun Feb 25, 2007
Author tomas Received 52 Replies #2890
Related Content
Related Pages
Related Sites
Add Your Website
Share
wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Wed Jun 19, 2013 (-8 GMT)
Powered by: Webune Forums V5