line count | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

line count

Shell Programming and Scripting


Tags
awk, grep -c

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-18-2010
j_panky j_panky is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 27 October 2011, 12:00 AM EDT
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
line count

Hello
I just need the line count of the file...
the file is too huge and cant count manually..
Of course i did

Code:
wc -l

But this simply got stuck..
Any suggestion...
Tried plenty of option, i know its easy, browsed the google but was not satisfied...
Sponsored Links
    #2  
Old 08-18-2010
ranjithpr ranjithpr is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 20 August 2010, 3:34 AM EDT
Posts: 175
Thanks: 0
Thanked 3 Times in 3 Posts
Below commands also will give the line count, but no idea about its perfomance.


Code:
grep -c "\n" filename


Code:
awk 'END {print NR}' filename

Sponsored Links
    #3  
Old 08-18-2010
j_panky j_panky is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 27 October 2011, 12:00 AM EDT
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
sorry but iam confused, as grep gives different output compare to awk...
    #4  
Old 08-18-2010
ranjithpr ranjithpr is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 20 August 2010, 3:34 AM EDT
Posts: 175
Thanks: 0
Thanked 3 Times in 3 Posts
Both the commands gave me same output in small file. But I think awk is accurate than grep.
Sponsored Links
    #5  
Old 08-18-2010
j_panky j_panky is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 27 October 2011, 12:00 AM EDT
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
iam not...that means there is some other way to do it....
My files is a huge file...
need to know the exact line count...
Sponsored Links
    #6  
Old 08-18-2010
guruprasadpr's Avatar
guruprasadpr guruprasadpr is offline Forum Advisor  
Shrink...ing
 
Join Date: Jun 2009
Last Activity: 15 April 2014, 5:07 AM EDT
Location: India
Posts: 675
Thanks: 30
Thanked 215 Times in 214 Posts
Hi

Not sure about the performance. But you can check the other options available here: Different ways to count total lines in a file.

Guru.
Sponsored Links
    #7  
Old 08-18-2010
ygemici ygemici is offline Forum Advisor  
sed_shell@LNU
 
Join Date: Feb 2010
Last Activity: 23 July 2014, 7:58 AM EDT
Location: istanbul
Posts: 1,671
Thanks: 2
Thanked 285 Times in 278 Posts
Quote:
Originally Posted by j_panky View Post
iam not...that means there is some other way to do it....
My files is a huge file...
need to know the exact line count...
did you try

Code:
 
# sed -n '$=' hugefile

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Line count using awk siba.s.nayak UNIX for Dummies Questions & Answers 3 07-16-2010 07:05 AM
Append line count to each line jaysean Shell Programming and Scripting 4 06-26-2010 01:43 AM
Count tab in a line sandy1028 Shell Programming and Scripting 4 06-15-2010 03:54 AM
Count on every other line red baron UNIX for Dummies Questions & Answers 4 07-19-2008 10:28 PM
Get the line count from 2nd line of the file ? smc3 Shell Programming and Scripting 8 06-16-2008 10:59 PM



All times are GMT -4. The time now is 02:44 AM.