[NTLUG:Discuss] Counting key presses in a file...

Stuart Johnston saj at thecommune.net
Mon Aug 27 16:08:34 CDT 2007


Richard Geoffrion wrote:
> I know that 'wc' can count words and lines, but how would one count.  
> While 'a' would constitute ONE keystroke, 'A' would constitute two. 
> (Shift + a).     Carriage returns would count as one while bolding text 
> would constitute four keystrokes as one would need a CTRL-B to turn 
> bolding on and another to turn bolding off.
> 
> How would one go about taking an openoffice document saved in the 
> 97/2000 'Word' format and converting it into something that can be 
> parsed and counted?

You'd probably have better luck parsing an OO file, if you want to stay 
in Linux.  You could use something like:
http://search.cpan.org/~jmgdoc/OpenOffice-OODoc-2.035/

You might also consider writing some kind of macro in OO/Word.

Realistically speaking, you'd probably want to save it as plain text and 
forget about your bolds and such.  You'd need some way to save it 
without wrapping though.

wc seems to count newlines as one character so, you're good there.  Run 
wc once to get your characters + newlines.  Then use sed/awk/perl to 
remove all the lower-case characters and newlines.  Run wc again and add 
the two together.  Considering you are never going to get something 
exact, that would get you pretty close.



More information about the Discuss mailing list