Sujet : Re: a sed question
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shellDate : 21. Dec 2024, 17:14:36
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vk6phd$4ck5$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 21.12.2024 16:34, Andy Walker wrote:
On 21/12/2024 12:17, Salvador Mirzo wrote:
I'm studying and I often go back to the past to see what life was I
like. I initially tried to solve the problem with /ed/, but did not
find a way to insert a string coming from the a shell script's cmdline.
Then I thought that /sed/ was there to make /ed/ more scriptable.
I think the other contributors are somewhat harsh on Sed. For
those who started on V6 Unix, there was just Ed, and, as you thought,
Sed was added in V7 as a scripting improvement to Ed.
If all you have is Sed, Sed may look fine.
If you had invested a lot time to learn or master Sed you're of course
less objecting to Sed.
Awk also came
in with V7. Some people adopted Awk with enthusiasm, but the early
versions were quite limited/buggy, partly thanks to the limitations of
the PDP-11; Sed was pretty reliable even in those days.
You should mention that you are speaking of the 1977 version of AT&T
Awk (released in 1979); that [buggy] version appeared 45 years ago!
The Awk standard (1992) is based on the 1985 version (released 1987);
yet also already 37 years ago, the Awk POSIX standard 32 years ago.
The GNU Awk version was introduced 1986; it is continuously supported
(and is meanwhile available in version 5.x).
So at least some users tried and failed with Awk,
(There was obviously plenty of time to not need to stick to Sed.)
but found Sed usable with very
little to learn, thanks to the relationship with Ed. The arcana of
Sed are much easier to understand if you are/were a regular user of Ed,
whereas Awk requires you to learn a whole new language [I'm not in any
way suggesting that that is unusually difficult].
Spreading FUD (bugs in the first release, whole new language) is not
appropriate here! - Awk is stable now since decades and the language
is extremely terse and with an excellent power/complexity ratio!)
A few more things should be pointed out in that respect...
At Washington University St. Louis there was an examination made how
long it requires to learn Awk; the result was that in one laboratory
50% of the students considered themselves being confident with Awk,
after a week it were 90% of the students.
Awk's syntax is extremely simple. The imperative actions resemble the
"C" language, so they're easy for the many users knowing any language
that was [syntactically] derived from "C" (but far more simple).
The few syntax elements are also readable - no cryptic abbreviations
as in Sed - so they are easily memorable.
I'm sure if one is constantly working with Sed that at some point he
will also have the [cryptic] Sed language incorporated.
So students will normally no longer learn or use Ed/Sed, apart
perhaps from "s/foo/bar/" and similar; it makes more sense to learn a
visual editor and Awk. But for older hands, and for those interested
in the history, there is still a use for Sed. Personally, I know my
way around Sed much better than Awk. So, again personally, Sed is my
stream editor of choice for tasks somewhat harder than "s ...", but not
so hard that I need to do some serious programming and checking of the
documentation. [YMMV, and I'm certainly not trying to persuade any Awk
users that they should learn to use Sed instead.]
Fair enough.
For newbies, as the OP seems to be, the personal historic experience
with Sed is not that useful, though. Since he now has the choice he
should take the most appropriate tool.
I also don't think that any of the negative responses concerning Sed
had meant to express any disrespect of Sed users.
Janis