[TxMt] Word Count

Hans-Jörg Bibiko bibiko at eva.mpg.de
Tue May 27 22:50:37 UTC 2008


On 28.05.2008, at 00:34, Hans-Jörg Bibiko wrote:
> On 27.05.2008, at 23:24, Mark Eli Kalderon wrote:
>> On May 27, 2008, at 10:11 PM, Jonas Steverud wrote:
>>> 20 maj 2008 kl. 20.07 skrev Patrick McElhaney:
>>>> CTRL+SHIFT+N. It's in the "Text" bundle.
>>>
>>> One should make a note though that C-S-N doesn't return the  
>>> number of characters, but the number of bytes. This is only an  
>>> issue if you use multi-byte character, which is commonly enough  
>>> to make the C-S-N command a bit broken IMHO.
>
> Firstly only a short answer to count Unicode characters:
>
> cat | ruby -e 'print STDIN.read.split(//u).size'
>
> input: selection or doc
> output: Show Tooltip

Maybe better:

#!/usr/bin/ruby

bytes=chars=words=lines=0

STDIN.read.each_line { |l|
	lines+=1
	bytes+=l.split(//).size
	chars+=l.split(//u).size
	words+=l.split(/ +/).size
}

puts("Bytes:      #{bytes}")
puts("Characters: #{chars}")
puts("Words:      #{words}")
puts("Lines:      #{lines}")

One could output it much more prettier ;)

--Hans


More information about the textmate mailing list