Nawk command to output in var

Hi

I have this command, which counts number of lines in a specific file and then prints it on screen.

nawk 'NF{c++}END{print "Number of GPS coordinates in file: "c}' $filename

I would like to have the output put into a variable, but can't seem to find the correct argument for it.

How do I manage that ?

Thanks in advance

my_variable=$(nawk 'NF{c++}END{print "Number of GPS coordinates in file: "c}' $filename)
echo $my_variable

Ahh great, thanks alot...

Had tried different approaches without luck, was pretty sure i could be done... thanks :slight_smile:

A variant: store only the number.

cnt=$(nawk 'NF{c++}END{print c}' $filename)
echo "Number of GPS coordinates in file: $cnt"