How to print the number of characters in each line of a text file

vikas368 picture vikas368 · Jan 9, 2012 · Viewed 98.3k times · Source

I would like to print the number of characters in each line of a text file using a unix command. I know it is simple with powershell

gc abc.txt | % {$_.length}

but I need unix command.

Answer

Fred Foo picture Fred Foo · Jan 9, 2012

Use Awk.

awk '{ print length }' abc.txt