[colug-432] Rant About sed, Regex and the Web

Steve VanSlyck s.vanslyck at postpro.net
Sun May 17 10:11:29 EDT 2015


Rant follows. If you're not up for some immaturity on a Sunday morning,
it's OK, please press delete. Before that, once again, please accept my
appreciation for the tons of help you guys are giving me. I trust some
of you will relate.

Jim, who is always here, always helpful, asked me some good questions
about my one-liner,

sed -i.bak 's:(^Defaults\s*Env_reset\s*)$:$1\nDefaults
editor=/bin/nano:' ./sudoers

, one of which was why "$1?"

For the "replace" portion of sed, I was trying to find out how to return
the result of the last search and $1 seemed to be the right way to do
it. I saw what I thought was a authoritative page on this but cannot
find it now. One that I did find is
http://stackoverflow.com/questions/2890700/backreferences-syntax-in-replacement-strings-why-dollar-sign
.

Everything I'm readying about regular expressions talks about this
engine does it this way and that engine does it that way and it's all
very confusing and frustrating. None of the "engines" are
fedora-based bash, so I have no idea which engine's requirements I'm
supposed to go by.

On top of this I have to struggle with a problem endemic to technical
writing and which is far too common: writers who state a rule and then
give examples inconsistent with the rule just described!

This makes me scream. I've seen it in so-called textbooks and
well-regarded non text-books on mathematics such as 1089 and All That.
It usually results in uncharitable thoughts about the author followed by
some profanity and an addition to the trash can. On grymoire.com, for
example, Bruce Barnett writes, "If you need to match a "^" at the
beginning of the line, or a "$" at the end of a line, you must escape
the special character with a backslash." Hard rule, got it, I'm good,
let's read on...and then he follows it up with THESE examples!:

^A matches "A" at the beginning of a line A$ matches "A" at the end of
a line A^ matches "A^" anywhere on a line $A matches "$A" anywhere on a
line ^^ matches "^" at the beginning of a line $$ matches "$" at the
end of a line

WT#! It maybe would've killed him to mention escaping the character OR
doubling it, and then give BOTH examples?:

^^ or \^ matches "^" at the beginning of a line $$ or \$ matches "$" at
the end of a line

How are we supposed to learn anything if we can't trust our teachers!

I'm almost 60. I approach this stuff in good faith, with no math
training beyond high school, no programming experience beyond Excel, a
little BASIC as a teenager* in the 70's, and an introduction to Visual
Basic course at DeVry in 2003 (where I got high marks for both coding
and commenting), and every time I try to learn something I run into
walls because the teachers won't do in English what they do in code!

Anyway, thank you for listening. I'm not going to give up this time.



Steve

*This was the first time I gave up on trying to learn something by
reading the documentation. The page in my TRS-80 manual said something
like print(string) and absolutely NOWHERE in the book was there the
least little hint that the correct syntax was print("string"). I
struggled with it for days, believing those people, before finally
giving up. To my credit, I did not blame myself.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20150517/ac49718f/attachment.html 


More information about the colug-432 mailing list