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..

Recommended Answers

All 4 Replies

wc -l

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}'`

well, don't even have to use wc.

number_of_line=$(awk 'END {print NR}' file)

Thanks for all these nice sharings..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.