Ability to store number of rows

Hi,

I am creating a korn shell script and i'm trying to find out what the total number of rows are in a specific text file and i need to store that number in a variable withing the script.

i know wc -l gives you the number, but it also has some leading spaces and then writes out the file name as well. All i need is the actual number or rows.

Also, i believe awk has the ability to return this value, but not sure how to store the value in a variable.

thanks
scott

Some ways to do this - the "lines" variable will have the line count

wc -l filename | read dummy lines
lines=$(sed -n '$=' filename)
lines=$(awk 'END{ print NR}' filename)
lines=$( wc -l < filename )
1 Like