ed in linux?

38 views
Skip to first unread message

Siri Cruise

unread,
Feb 19, 2022, 6:42:15 AMFeb 19
to
I want to conditionally edit a file in a makefile: if the file
has 'xyzzy' the file should not be changed. The make action is
akin to

(echo 'g/xyzzy/q'; \
echo 'more ed commands' \
echo ... \
echo wq) | ed file

On macosx, this works as expected: if the 'xyzzy' is anywhere in
the file, ed quits on the first command, the file is unchanged,
ed exit code is 0 and make continues.

On linux, the g fails (prints ?) and ed exits with a failure exit
code.

Does anyone have a suggestion so linux ed act like macos ed?


ob-irrlevqnt-rage-at-the-sky f*** this dying jeyboard!!!

--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Doria sockpuppet. insults Islam. Mohammed

Ben Bacarisse

unread,
Feb 19, 2022, 12:44:43 PMFeb 19
to
Siri Cruise <chine...@yahoo.com> writes:

> I want to conditionally edit a file in a makefile: if the file
> has 'xyzzy' the file should not be changed. The make action is
> akin to
>
> (echo 'g/xyzzy/q'; \
> echo 'more ed commands' \
> echo ... \
> echo wq) | ed file

It's the ;. This works for me:

(echo 'g/xyzzy/q
another cmd
and another
w
q
') | ed file

But I'd consider some other way myself. Something like

grep -q xyzzy file || some other command to edit the file

BTW,

printf "%s\n" l1 l2 l3 | ed file

is a simple way to get the newlines.

--
Ben.

Siri Cruise

unread,
Feb 19, 2022, 2:32:13 PMFeb 19
to
In article <87r17yd...@bsb.me.uk>,
Ben Bacarisse <ben.u...@bsb.me.uk> wrote:

> Siri Cruise <chine...@yahoo.com> writes:
>
> > I want to conditionally edit a file in a makefile: if the file
> > has 'xyzzy' the file should not be changed. The make action is
> > akin to
> >
> > (echo 'g/xyzzy/q'; \
> > echo 'more ed commands' \
> > echo ... \
> > echo wq) | ed file
>
> It's the ;. This works for me:
>
> (echo 'g/xyzzy/q
> another cmd
> and another
> w
> q
> ') | ed file
>
> But I'd consider some other way myself. Something like
>
> grep -q xyzzy file || some other command to edit the file

That requires hunting down the makefile segments and driving
stqkes through their hearts, which I hoped to void.

'You Americans. You make everything so simple so complicated.'

Ben Bacarisse

unread,
Feb 19, 2022, 3:46:22 PMFeb 19
to
Siri Cruise <chine...@yahoo.com> writes:

> In article <87r17yd...@bsb.me.uk>,
> Ben Bacarisse <ben.u...@bsb.me.uk> wrote:
>
>> Siri Cruise <chine...@yahoo.com> writes:
>>
>> > I want to conditionally edit a file in a makefile: if the file
>> > has 'xyzzy' the file should not be changed. The make action is
>> > akin to
>> >
>> > (echo 'g/xyzzy/q'; \
>> > echo 'more ed commands' \
>> > echo ... \
>> > echo wq) | ed file
>>
>> It's the ;. This works for me:
>>
>> (echo 'g/xyzzy/q
>> another cmd
>> and another
>> w
>> q
>> ') | ed file
>>
>> But I'd consider some other way myself. Something like
>>
>> grep -q xyzzy file || some other command to edit the file
>
> That requires hunting down the makefile segments and driving
> stqkes through their hearts, which I hoped to void.

You were looking for a way to make Linux ed support a different command
syntax? I think you are out of luck with that.

> 'You Americans. You make everything so simple so complicated.'

What have Americans got to do with the price of fish? Did an American
write the makefile? Piping to ed has long been considered an
anti-pattern.

--
Ben.

Eric Pozharski

unread,
Feb 21, 2022, 5:33:19 AMFeb 21
to
with <87r17yd...@bsb.me.uk> Ben Bacarisse wrote:
> Siri Cruise <chine...@yahoo.com> writes:

>> I want to conditionally edit a file in a makefile: if the file has
>> 'xyzzy' the file should not be changed. The make action is akin to
>>
>> (echo 'g/xyzzy/q'; \
>> echo 'more ed commands' \
>> echo ... \
>> echo wq) | ed file
>
> It's the ;. This works for me:

Let me stir into this higly intellectual discussion. Here comes:

This is fscked up on so many levels.

ben.usenet@, whatever you're doing works for you because you're running
same ed(1) as that of macos. chine.bleu@ has no problems with BSD ed,
they have problems with GNU ed. See where it's going?

chine.bleu@, GNU ed doesn't do any command suffixes except those that
print (namely, 'l', 'p', 'n') (because, "Just because?", I guess).
Second, neither of you copy-paste -- neither your commands nor your
files. Is it too much to ask for The Complete Minimal Example? One
might only wonder what are reasons behind first escaping newlines, then
breaking this (effectevely) single-line with semicolons.

*SKIP*

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Siri Cruise

unread,
Feb 23, 2022, 11:19:36 AMFeb 23
to
In article <slrnt16iod...@orphan.zombinet>,
Eric Pozharski <why...@pozharski.name> wrote:

> chine.bleu@, GNU ed doesn't do any command suffixes except those that
> print (namely, 'l', 'p', 'n') (because, "Just because?", I guess).

By command suffix you mean the '...' in 'g/re/...', correct?

[expletive deleted]. My alternative has been tclsh to read the
file, modify it with regsub etc, and write it back. I guess I'll
have to do that from now. ed doesn't do much, but it was easy to
invoke and I assumed would be universally equivalent on all
unices.

Scott Lurndal

unread,
Feb 23, 2022, 11:50:01 AMFeb 23
to
Siri Cruise <chine...@yahoo.com> writes:
>In article <slrnt16iod...@orphan.zombinet>,
> Eric Pozharski <why...@pozharski.name> wrote:
>
>> chine.bleu@, GNU ed doesn't do any command suffixes except those that
>> print (namely, 'l', 'p', 'n') (because, "Just because?", I guess).
>
>By command suffix you mean the '...' in 'g/re/...', correct?
>
>[expletive deleted]. My alternative has been tclsh to read the
>file, modify it with regsub etc, and write it back. I guess I'll
>have to do that from now. ed doesn't do much, but it was easy to
>invoke and I assumed would be universally equivalent on all
>unices.

All versions of ed should support what is defined here:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html

Have you investigated sed or awk as an alternative?

Specifically, note for the global command that Posix says:

"The use of the g, G, v, V, and ! commands in the command
list produces undefined results"

This is likely because the various flavors of ed(1) in existance
when the standard was written did not all handle those commmands
in the same way.

Note that the gnu ed(1) manpage explicitly states that those
commands are not allowed as part of the global command-list.

Any commands are allowed, except for 'g', 'G', 'v', and 'V'. By
default, a newline alone in COMMAND-LIST is equivalent to a 'p'
command.

Ralf Fassel

unread,
Feb 23, 2022, 12:54:57 PMFeb 23
to
* Siri Cruise <chine...@yahoo.com>
| In article <slrnt16iod...@orphan.zombinet>,
| Eric Pozharski <why...@pozharski.name> wrote:
>
| > chine.bleu@, GNU ed doesn't do any command suffixes except those that
| > print (namely, 'l', 'p', 'n') (because, "Just because?", I guess).
>
| By command suffix you mean the '...' in 'g/re/...', correct?
>
| [expletive deleted]. My alternative has been tclsh to read the
| file, modify it with regsub etc, and write it back. I guess I'll
| have to do that from now. ed doesn't do much, but it was easy to
| invoke and I assumed would be universally equivalent on all unices.

*headscratch* What's wrong with 'sed'? Though I don't know if that
suffers the same deficiencies between platforms as 'ed'...

R'

Kenny McCormack

unread,
Feb 23, 2022, 1:59:22 PMFeb 23
to
sed is just so ... weird.

Most sensible people recommend against using sed for anything other than
simple s/foo/bar/g usage. Once you get past that, things just start
getting weird.

Also, yes, I'm sure there's variation across platforms. Most people will
be used to the GNU version (of sed or anything else) and get used to using
GNU extensions, which leads to, well, you know...

In particular, one nice thing about using a real editor (such as "ed") in a
batch/scripted way (as opposed to using something more batch/script
oriented like "sed") is that it natively edits in place. That is, you
script it, and it writes back to the original file by default. With sed
and other batch/script oriented tools, you have to hem and haw to get "in
place" editing. (Yes, I know that it is a feature of GNU sed - thus, see
previous paragraph).

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/DanaC

Eric Pozharski

unread,
Feb 24, 2022, 5:33:18 AMFeb 24
to
with <chine.bleu-AD17C...@reader.eternal-september.org>
Siri Cruise wrote:
> In article <slrnt16iod...@orphan.zombinet>, Eric Pozharski
> <why...@pozharski.name> wrote:

>> chine.bleu@, GNU ed doesn't do any command suffixes except those that
>> print (namely, 'l', 'p', 'n') (because, "Just because?", I guess).
> By command suffix you mean the '...' in 'g/re/...', correct?

Wrong. *I* was wrong. Indeed, "suffixes" are for anything but 'g'
brotherhood. For those four it's "command-list". Still, 'q' is
*rejected* for unspecified reasons:

[0:0]% cat ~/foo.s6ckUi.txt
foo
bar
[0:0]% ed !$
ed ~/foo.s6ckUi.txt
8
H
g/foo/q
?

%n
1 foo
2 bar
q

> [expletive deleted]. My alternative has been tclsh to read the file,
> modify it with regsub etc, and write it back. I guess I'll have to do
> that from now. ed doesn't do much, but it was easy to invoke and I
> assumed would be universally equivalent on all unices.

In last 12 month I've went through sources of pdns-recursor, dcron
(fscking vaporware), pppd, comgt, perl, and zsh. I don't know what are
you talking about and I'm not interested. I'm burnt out. I'm glad you
realized the dead-end early enough.

Lew Pitcher

unread,
Feb 24, 2022, 9:12:15 AMFeb 24
to

> In last 12 month I've went through sources of pdns-recursor, dcron
> (fscking vaporware),

I'm curious. Can you elaborate on "dcron (fscking vaporware)"?

> pppd, comgt, perl, and zsh. I don't know what are
> you talking about and I'm not interested. I'm burnt out. I'm glad you
> realized the dead-end early enough.

Just eavesdripping ;-)
--
Lew Pitcher
"In Skills, We Trust"

Eric Pozharski

unread,
Feb 25, 2022, 1:33:19 PMFeb 25
to
with <sv83np$lbf$1...@dont-email.me> Lew Pitcher wrote:

>> In last 12 month I've went through sources of pdns-recursor, dcron
>> (fscking vaporware),
> I'm curious. Can you elaborate on "dcron (fscking vaporware)"?

So, I need anacron themed functionality. I've fantasized about doing it
without anacron itself. Alegedly, dcron has ID=, AFTER=, EAGAIN, and
FREQ= -- thus, I have all building blocks I need. Or so I thought.

I dont't have distinct memory if AFTER= works ((probably it does),
problem is I've not reached that far because:

* EAGAIN works *only* if logging is at level DEBUG. Otherwise, errno=11
is treated like any other not null.

* FREQ= doesn't work at all. Like, it's illigal syntax.

Upon inspecting sources, I've discovered about 2/3 of EAGAIN code is
commented out. All about FREQ= code is commented out.

Otherwise, as minimal crond dcron is fine. I was so close.

>> pppd, comgt, perl, and zsh. I don't know what are you talking about
>> and I'm not interested. I'm burnt out. I'm glad you realized the
>> dead-end early enough.
> Just eavesdripping ;-)

Funny thing, comgt works indeed. Docu is so terrible, I just don't know
what to expect.
Reply all
Reply to author
Forward
0 new messages