Get the line number in shell script

I have one text file

1 2 3
   a 5
4  4 3

where i want to print the line number

while read line 
do
line_no=`awk '{print NR, $0}'`
echo 'In line no $line_no'
done <$txt_file 

If i run the above code, it will print
'In line no 1 1 2 3'

It prints the line number with the whole line.But I want to print only the line number

In line no 1
In line no 2
In line no 3 
awk '{print "In line no " FNR}' $txt_file

May I doubt that? Running that code as is will print In line no $line_no . Changing the single quotes around the echo command to double quotes will print

In line no 1    a 5
2 4  4 3

, as those enable variable expansion. $line holds 1 2 3 from the first read , $line_no contains

1    a 5
2 4  4 3

, i.e. NR and $0 from the rest of the input file redirected from stdin. The while loop is exited after the first iteration. This is because read and awk both read from the input file, and awk loops through it until it's exhausted.

Use tools consistently, either awk only as proposed by vgersh99, or pure shell like

while read line; do echo "in line $((++CNT))"; done < file1
in line 1
in line 2
in line 3

Here an additional variable needs to be deployed as the shell doesn't provide a line count for stdin by itself.

You may find nl command useful