shell script to cap first letter?

b. f. bf1783 at
Sun Mar 21 14:16:25 UTC 2010

>i'm wondering if there is a script that i could run my plaintext
>files thru that would capitalize thef first letter of each
>sentence [[ assuming the character wasn't already a cap!]]
>more and more, in recent years, i have posted questions or
>written things that have been sloppily or casually hacked
>together in all lower case.  this filter would have to determine
>what was and was not a sentence.  or a sentence fragment.
>[ai]spell can catch "i've" and suggest "I've", etc.

You're asking a lot from a simple filter if you want it to
discriminate between uses of "." to terminate a sentence, and other
uses of "." that do not require the following word to be capitalized,
such as the use of "." in abbreviations -- a lot of fairly
sophisticated spelling and grammar checkers can fail to do this
reliably.  But if you want a naive filter you could use textproc/gsed,
with the /U GNU extension (our BSD sed(1) doesn't understand it),

gsed -e 's|\(\.[.[:space:].]\)\([a-z]\)|\1\U\2|g'

or you could use BSD sed(1), together with a more cumbersome
capitalization script, like the cflword[12345].sed scripts at:

Or you could use Perl.  Or awk(1). Or script a [non-]interactive call
to a more sophisticated spelling or grammar checker. Or roll your own.
 For questions like this, try searching the web first.


More information about the freebsd-questions mailing list