User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,423 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,609 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1034 | Replies: 4
Reply
Join Date: Jan 2006
Location: Balkh
Posts: 67
Reputation: jamshid is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jamshid's Avatar
jamshid jamshid is offline Offline
Junior Poster in Training

Help Find the total lines in the file

  #1  
Apr 12th, 2007
hi DW Shell Script Kings

i have some problem in a step of my assignment.

thats i can read the file with this :

#Read all text from file

echo -n "Enter file name: "
read fileName

while read inputline
do
echo $inputline
done < $fileName

how i can find the total lines which is in this file ??

i mean like this : if the file has student names , it must output like this :

Total students : x


Thanks for helping..
Last edited by jamshid : Apr 12th, 2007 at 10:00 am.
Impossible is Nothing
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,509
Reputation: masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light masijade is a glorious beacon of light 
Rep Power: 10
Solved Threads: 136
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

Re: Find the total lines in the file

  #2  
Apr 12th, 2007
wc -l
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore, India
Posts: 535
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Rep Power: 4
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Find the total lines in the file

  #3  
Apr 16th, 2007
It's a common error to do:
number_of_lines=`wc -l file_name`

To be precise:
number_of_lines=`wc -l file_name | awk '{print $1}'`
Reply With Quote  
Join Date: Apr 2006
Posts: 140
Reputation: ghostdog74 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 26
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: Find the total lines in the file

  #4  
Apr 16th, 2007
well, don't even have to use wc.
number_of_line=$(awk 'END {print NR}' file)
Reply With Quote  
Join Date: Jan 2006
Location: Balkh
Posts: 67
Reputation: jamshid is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jamshid's Avatar
jamshid jamshid is offline Offline
Junior Poster in Training

Re: Find the total lines in the file

  #5  
Apr 17th, 2007
Thanks for all these nice sharings..
Impossible is Nothing
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC