Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

line count

Shell Programming and Scripting


Tags
awk, grep -c

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 Unix and Linux 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 Unix and Linux 08-18-2010
guruprasadpr's Unix or Linux Image
guruprasadpr guruprasadpr is offline Forum Advisor  
Shrink...ing
 
Join Date: Jun 2009
Last Activity: 1 December 2014, 8:24 AM EST
Location: India
Posts: 676
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 Unix and Linux 08-18-2010
ygemici ygemici is offline Forum Advisor  
sed_shell@LNU
 
Join Date: Feb 2010
Last Activity: 30 April 2015, 2:41 AM EDT
Location: istanbul
Posts: 1,701
Thanks: 4
Thanked 290 Times in 282 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 08:30 AM.