mdb@ESD.3Com.COM (Mark D. Baushke) (09/02/90)
On 1 Sep 90 13:06:34 GMT, in article <3245@nems.dt.navy.mil> posted
to comp.emacs, science@nems.dt.navy.mil (Mark Zimmermann) writes:
Mark> does anybody have (a pointer to) an Emacs way to convert ALL CAPITAL
Mark> LETTER TEXT into nice mixed-case text? There are obviously many
Mark> degrees of sophistication in doing this; I'd like to be able to give
Mark> the system a file of words to be capitalized and/or words to be
Mark> lowercased and/or words to be all caps (NASA, USA, etc.), to
Mark> customize, and it should try to find and capitalize the first word of
Mark> each sentence. Any suggestions?? Is this better done in C or awk
Mark> than in Emacs?? Tnx for help! - ^z - science@nems.dt.navy.mil
The perl script after my .signature was posted to comp.lang.perl some
time ago. With a little work it should be possible to add an exception
list for some words like NASA, USA, etc. to be output in all caps.
Enjoy!
--
Mark D. Baushke
mdb@ESD.3Com.COM
#!/usr/bin/perl
# This program copies its input to STDOUT, converting uppercase characters
# to lowercase, except the first letter of each sentence and the word 'I'.
# DEFINITION: a 'sentence' begins with an alphanumeric and ends at the end
# of the input file or at the first terminator (period, question mark, or
# exclamation point) which is followed by white space.
$/ = "\177"; # do not split the input into lines
$_ = <>; # read the entire input
s/(\w)(([^.?!I]+|[.?!]+\S|\BI|I\B)+)/($a=$2)=~tr|A-Z|a-z|,$1.$a/eg;
print; # print the results