I am having issues understanding why my code counts like it does. I use the following code to calculate the sum of lengths of all lines.
awk '{cnt += length($0)} END { print cnt/NR}' text.txt
In my text file i have the following.
hello
hellohello
There is no space between the sentences in the actual text file.
For example why would get i the value of 16 when i run code below and not 15
awk '{cnt += length($0)} END { print cnt }' text.txt
I understand that the count of 16 is divided by 2 because NR(numbers of lines)in my original count. But why does it count an extra character when i have 15 in the text file? When i edit my text file differently i get different results. If i end on a empty line(hit enter after "hellohello") it also counts that one towards the total count, then i would get 17.
Basically i need someone to help me and explain what exactly its counting and why.