[conspire] RElief: Re: CAPS - eyes hurt, ...

Michael Paoli Michael.Paoli at cal.berkeley.edu
Wed Dec 19 04:59:49 PST 2018


> From: "Alex Kleider" <akleider at sonic.net>
> Subject: Re: [conspire] RElief: Re: CAPS - eyes hurt
> Date: Tue, 18 Dec 2018 23:45:59 -0800

> On 2018-12-18 23:06, Michael Paoli wrote:
>>> Date: Tue, 18 Dec 2018 15:59:20 -0800
>>> From: Rick Moen <rick at linuxmafia.com>
>>> To: conspire at linuxmafia.com
>>> Subject: Re: [conspire] successful install, at last
>>>
>>> Quoting Paul Zander (paulz at ieee.org):
>>>
>>>> REPLIES BELOW, ALL IN CAPS
>>>
>>> Wow, my eyes hurt.
>>
>> Ouch ...
>> Fortunately we have effective treatments for that, e.g. RElief can
>> be provided by REs - Regular Expressions ...
>> Which, e.g., can all be done in lovely vi(1),
>
> I very much admire Michael's facility with Unix tools.
> Another approach that might be easier to implement:
>
> ======== my little script =======
> # File: nouppers.py
>
> """
> Usage:
>    python nouppers.py infile [> outfile]
>
> Prints infile with all uppercase letters changed to lowercase.
> Output can be redirected to a separate file.
> """
>
> import sys
>
> infile = sys.argv[1]
> with open(infile, 'r') as file_object:
>     text = file_object.read()
> nouppers = text.lower()
> # print nouppers # Use this line if running python2.7
> print(nouppers)  # Use this line if running python3
>
> ============================================
>
> Alex
>
> ps script written using vim and then (after a modicum of testing)  
> copy/pasted into text of email

Well, if all one wants to do is convert all uppercase to lowercase, that's
much simpler.  Let's see ... fewest # of typed characters I can use to
do that with a (more-or-less) POSIX/SUS compliant Unix(-like) system ...
tr A-Z a-z
:%s/./\l&/g
^ if I'm already in ex (or vi in ex mode) I don't type the :
So that ties tr for fewest,
and that tr reads from stdin and writes to stdout.
Anyone have anything with fewer? ... well, short of invoking custom
script/program one has written or the like?

However the bit I'd shown:
:g/^[^a-z]*$/s/^.*[A-Z].*$/< \L&/
is much more specific ...
... that command, in vi(1), takes all lines that contain no lowercase letters
and at least one uppercase letter, and prepends < and space to the line
and changes all the uppercase letters to lowercase on that line.
So most notably, it's much more selective - it doesn't convert lines to
lowercase if they already contain a lowercase letter.  And it additionally
does the "< " prepending (just 'cause I felt like it).  A bit more
reader friendly would've been to prepend "> " to all lines not matching
having (has uppercase characters but no lowercase characters),
and for all the other lines, convert entirely to lowercase (oh, and
maybe also excepting i when it looks like it's used as a personal pronoun).
But of course, even my simpler but more selective lowercasing is bit
more complex and selective than lowercasing everything.
Some years back, I did write wee bit 'o script (probably for sed?  Or
Perl?) that took some horribly (un)formatted emails or similar text, and
did some automagic reformatting to make the stuff more readable (e.g.
turning i, when it looked like it was used as personal pronoun, into I,
putting 2 spaces between sentences when only one was present, fixing some
common egregious annoying misspellings commonly(/chronically) used by
certain author(s), etc.  Ah yes, ... still have that about ...
See: reformat on:
http://www.rawbw.com/~mp/perl/
http://www.rawbw.com/~mp/perl/reformat
$ wget -q -O - http://www.rawbw.com/~mp/perl/reformat | expand -t 4 |  
sed -ne '/^while/,/^{/{/^while/d;/^}/d;s/^    //;p;}'
chomp;
                                     # generally (there are exceptions)
s/([.!?])(?![]) .!?]|$)/\1  /go;    # two spaces after sentence end
s/([,;])(?![]) ,;]|$)/\1 /go;       # space after , or ;
s/&(?! |&|$)/& /go;                 # space after &
s/([^ &])&/\1 &/go;                 # space before &
s/([[:alpha:]][.!?]*)\(/\1 (/go;    # space before (
s/\)([[:alpha:]])/) \1/go;          # space after )
s/( |^|^~)(i)(m)(?=[.!? ]|$)/\1\2'\3/igo;   # im --> i'm
s/( |^|^~)(don)(t)(?=[.!? ]|$)/\1\2'\3/igo; # dont --> don't

if($case){
                                     # if we're doing case conversions ...
                                     # generally (there are exceptions)
     s/[[:upper:]]/\l$&/go;                      # to lowercase
     s/(^|[.!?] +)[[:lower:]]/\U$&/go;           # sentence start upper
     s/( |^|^~)i(?=[.!? ]|$)/\1I/go;             # i --> I
     s/( |^|^~)i'(ll|m|ve)(?=[.!? ]|$)/\1I'\2/go;# i'll/i'm/i've -->  
I'll/I'm/I've
};

print "$_\n";
$





More information about the conspire mailing list