AWK: Cannot read Number of records greater than 1(NR>1)

Hi all,

I have a tab-delimited text file of size 10Mb. I am trying to count the number of lines using,

grep -c . sample.txt

or

wc -l < sample.txt

or

awk 'END {print NR}'  sample.txt

All these commands shows the count as 1, which means they are reading only the first header line of the file. None of the commands are giving the correct count of lines.

Could anyone help to get the count of all lines in the file using awk. A sample file is attached for reference.

Run

perl -pe 's/\r/\n/g' sample.txt > sample2.txt

Then

wc -l sample2.txt
1 Like

Actually, it means, there's no new lines as they understand it.

Would this work?

awk 'BEGIN{ RS="\r" } END{print NR}' sample.txt
2 Likes

Thanks!! it worked.