You can use `nl` to number the lines of the file before going through them:
$ cat testfile
a
b
c
$ nl -b a testfile
1 a
2 b
3 c
Note that `-b a` is required because, by default, `nl` doesn't number blank lines.
Of course, this will be inefficient if your file is very large as it will go through the file twice.
Perhaps a better alternative is to use your own line counter so that you need only go through the file once:
COUNT=0
while read -r line; do
COUNT=$(( $COUNT + 1 ))
if [ ... ];then
# Do things to the line
# Make use of COUNT to show line number
fi
done < your_file_here
This will only work if you're processing the file line-by-line. It won't work if you're using `grep` for example.