Skip to main content
5 of 5
added 88 characters in body
muru
  • 381
  • 1
  • 8

POSIX awk, 79 75 67 65 bytes

{w+=NF;c+=length+1}END{d=length(c)"d %";printf"%"d d"d\n",NR,w,c}

Edit: saved 4 bytes since POSIX allows a bare length, saved 7 bytes by discounting the invocation part, and saved two bytes thanks to Doorknob's tip for adding d % to d.

This was originally for GNU awk, but best I can tell, it uses only POSIX awk functionality.

Better formatted:

gawk '{
  w += NF
  c += length($0) + 1  # length($0) misses the newline
}
END {
  d = length(c) # GNU awk's length returns the length of string representation of number
  printf "%"d"d %"d"d %d\n", NR, w, c
}'
muru
  • 381
  • 1
  • 8