line break is not counted in character count
I have a following code that counts the number of characters in a file
using awk.
but it doesn't count the line breaks as it is counted in $ wc file
file:abc
12345
12345
12345
12345
12345
awk command:
$ awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++)c++}END{print "total chars:"c}' abc
This gives me o/p as
Total char:25
but if i run same abc file as wc abc it gives me o/p as 30 characters
No comments:
Post a Comment