[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

sed:awk:perl::rock:paper:chainsaw [was Re: Using .XCompose]



On Thu, 16 Jul 2020 Ajith R wrote:
On Thursday 16 July 2020 4:54:09 AM IST davidson wrote:

[snip]
   $ sed 'y/\xc2\xa0/%/' somefile

An off topic question: of sed, awk and perl, if I am to chose one to
learn, which would you suggest. I wanted to do some substitutions. I
read about them and decided on PERL because from what I understood,
it has better support for regular expressions and do almost
everything that sed and awk could do. Have I made the right
decision?

This is sort of two questions in one.

First, there is a somewhat specific question about unspecified
substitutions. For all I know about these substitutions, you might
actually need XSLT to do them properly.

But then there is a more general invitation for advice on where to
invest time.

The second one is a little like one mechanic asking another:

  So erm, Carl. What's your signature ugly hack that you like to use
  to fix broken stuff in a totally unprofessional way? Glue? Duct
  tape?  Chewing gum?  I've been using this epoxy stuff for a while
  now, but I've heard some good things about chewing gum. Wanna tell
  me about it?

But first of all, I should reiterate that I lack expertise.

I lack expertise.

Second, I have no useful knowledge about real programming languages
(such as perl) to declare.

But as a peer, albeit a thick one who is not a perl-knowing brain
wizard, this is my experience:

IF

 1. I can fit it in less than 100 characters,
 2. it's a one-off task and
 3. I'm doing it from an interactive unix shell,

then I will sometimes use sed, most frequently to edit configuration
files. But I consider it a strictly write-only language.

Once I've written it, reviewed it carefully, tested that it does what
I intend, then I use it, check the results and forget I ever saw it.

If it gets more complex than that, and especially if I will ever have
to look at it again, then awk is a likely candidate if pattern-action
templates are the way to go and if the input is mere plain text (not
xml or something like that).

But wait. Let's back up a little.

First of all, why am I using sed to edit config files? Seriously, why?

This is like asking why I'm licking the window. Must be because I LIKE
TO LICK THE WINDOW. No accounting for taste, so they say, and they are
correct. Windows are just so delicious.

Yo-yo mastery results from dedication to an absurd hobby, but hey,
people enjoy it. And more power to 'em. It's harmless, which is more
than can be said for sed abuse.

I would probably be better off if I kicked the sed habit and took up
the yo-yo. Maybe learning some awk was a step in the right direction
after all. But what is interesting to me is that it almost seems like
the *more* I learn about unix, the *less* use I find for either one of
sed or awk.

And for whatever my opinion is worth (spoiler: literally less than
zero) I think you should absolutely use perl if it makes you happy.

I suspect, though, that it could be worthwhile to ask yourself why you
*need* to use it, whenever it seems like you do. For example, I ended
up using sed 'y///' because tr is currently *broken*, when faced with
multi-byte characters.

Unix has a pretty interesting collection of various small tools (which
"do one thing and do it well" as you may hear), and shells facilitate
hooking up their outputs and inputs. Almost as if they were made to do
just that.

This has been tonight's edition of Sweeping Generalities. I'm Richard
Blowhard. Thank you for tuning in.

Good night.

--
Ce qui est important est rarement urgent
et ce qui est urgent est rarement important
-- Dwight David Eisenhower

Reply to: