Re: ed! the one true editor! (was Re: sed on a large file)

2022-12-12 Thread Les Kitchen via luv-main
On Tue, Dec 13, 2022, at 01:50, Craig Sanders via luv-main wrote:
...
>> ed ~/.ssh/known_hosts
>> 140d
>> wq
>>
>> That is, delete line 140, write and quit.
>
> or automate it with:
>
> printf '%s\n' 140 d w q | ed ~/.ssh/known_hosts

:-)
___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


Re: ed! the one true editor! (was Re: sed on a large file)

2022-12-12 Thread Craig Sanders via luv-main
On Sun, Dec 11, 2022 at 10:04:58PM -0800, Rick Moen wrote:
> Quoting Craig Sanders (c...@taz.net.au):
>
> > still useful) ed or ex. ed is the original unix text line editor, dating
> > back to 1969 and still included with modern unix & linux systems.
>
> It also famously had one of the most ultra-terse man pages in all of Unix,
> thus leading to this humour piece (now arguably obsolete now that Debian
> provided a rather more fleshed-out man page):

yeah, that was the inspiration for my subject line.

craig
___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


Re: ed! the one true editor! (was Re: sed on a large file)

2022-12-12 Thread Craig Sanders via luv-main
On Mon, Dec 12, 2022 at 05:21:29PM +1100, Les Kitchen wrote:
> I too will put in a good word for good old ed.  I wrote most of my Ph.D.
> thesis using ed through a dial-up acoustic modem, but that was a long time
> ago.

ed is awful for interactive use but very useful for scripted use (e.g. with
printf as in my previous message). ex is even better.

> Since then, I've used it for system rescue when no other editor was
> available.

It's better than nothing if that's all you've got. better than the even more
minimalist `cat > filename` too.

These days, though, disk space isn't much of an issue even for rescue disks or
an initramfs - it's rare not to have at least a minimal vi available (nvi or
elvis or similar). maybe even vim.

Or nano which (as much as I dislike it and other-editors-which-aren't-vi) is
better for interactive use than ed.


> And before ssh-keygen got the -R option, ed was the quickest and most
> convenient way to remove offending host lines from my ssh known_hosts file
> by something like:
>
> ed ~/.ssh/known_hosts
> 140d
> wq
>
> That is, delete line 140, write and quit.

or automate it with:

printf '%s\n' 140 d w q | ed ~/.ssh/known_hosts

craig
___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


Re: ed! the one true editor! (was Re: sed on a large file)

2022-12-11 Thread Les Kitchen via luv-main
On Mon, Dec 12, 2022, at 15:27, Craig Sanders via luv-main wrote:

> If you want to do an actual in-place edit (with edits being performed on the
> same file with the same inode), you could something like the ancient (but
> still useful) ed or ex. ed is the original unix text line editor, dating
> back to 1969 and still included with modern unix & linux systems. ex is
...

I too will put in a good word for good old ed.  I wrote most of
my Ph.D. thesis using ed through a dial-up acoustic modem, but
that was a long time ago.  Since then, I've used it for system
rescue when no other editor was available.  And before
ssh-keygen got the -R option, ed was the quickest and most
convenient way to remove offending host lines from my ssh
known_hosts file by something like:

ed ~/.ssh/known_hosts
140d
wq

That is, delete line 140, write and quit.

In-place editors normally have to slurp up the entire file into
(virtual) main memory (or do some similar trick using temp
files).  I was a bit worried that ed's internal data structures
might break on too big a file, but I was able to slurp up an
approximately 4GB file:

athena(ljk) time ed /tmp/foo.foo
4248829952
q

real4m44.176s
user1m0.899s
sys 0m18.682s

This was on an x86_64 machine.  You might run into problems with
a smaller word size.


— Smiles, Les.
___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


Re: ed! the one true editor! (was Re: sed on a large file)

2022-12-11 Thread Rohan McLeod via luv-main

Rick Moen via luv-main wrote:

Quoting Craig Sanders (c...@taz.net.au):


still useful) ed or ex. ed is the original unix text line editor, dating
back to 1969 and still included with modern unix & linux systems.

It also famously had one of the most ultra-terse man pages in all of
Unix, thus leading to this humour piece (now arguably obsolete now that
Debian provided a rather more fleshed-out man page):



From: p...@athena.mit.edu (Patrick J. LoPresti)
Message-ID: <1991jul11.031731.9...@athena.mit.edu>
Sender: n...@athena.mit.edu (News system)
Subject: The True Path (long)
Date: 11 Jul 91 03:17:31 GMT
Path:
ai-lab!mintaka!olivea!samsung!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!patl
Newsgroups: alt.religion.emacs,alt.slack
Organization: Massachusetts Institute of Technology
Lines: 95
Xref: ai-lab alt.religion.emacs:244 alt.slack:1935

When I log into my Xenix system with my 110 baud teletype, both vi
*and* Emacs are just too damn slow.  They print useless messages like,
'C-h for help' and '"foo" File is read only'.  So I use the editor
that doesn't waste my VALUABLE time.

Ed, man!  !man ed

ED(1)   UNIX Programmer's ManualED(1)

NAME
  ed - text editor

SYNOPSIS
  ed [ - ] [ -x ] [ name ]
DESCRIPTION
  Ed is the standard text editor.
---

Computer Scientists love ed, not just because it comes first
alphabetically, but because it's the standard.  Everyone else loves ed
because it's ED!

"Ed is the standard text editor."

And ed doesn't waste space on my Timex Sinclair.  Just look:

-rwxr-xr-x  1 root  24 Oct 29  1929 /bin/ed
-rwxr-xr-t  4 root 1310720 Jan  1  1970 /usr/ucb/vi
-rwxr-xr-x  1 root  5.89824e37 Oct 22  1990 /usr/bin/emacs

Of course, on the system *I* administrate, vi is symlinked to ed.
Emacs has been replaced by a shell script which 1) Generates a syslog
message at level LOG_EMERG; 2) reduces the user's disk quota by 100K;
and 3) RUNS ED!!

"Ed is the standard text editor."

Let's look at a typical novice's session with the mighty ed:

golem> ed

?
help
?
?
?
quit
?
exit
?
bye
?
hello?
?
eat flaming death
?
^C
?
^C
?
^D
?

---
Note the consistent user interface and error reportage.  Ed is
generous enough to flag errors, yet prudent enough not to overwhelm
the novice with verbosity.

"Ed is the standard text editor."

Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA!  ED HAS BEEN THE CHOICE OF EDUCATED
AND IGNORANT ALIKE FOR CENTURIES!  ED WILL NOT CORRUPT YOUR PRECIOUS
BODILY FLUIDS!!  ED IS THE STANDARD TEXT EDITOR!  ED MAKES THE SUN
SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless
help screens and cursor positioning code!  I just want an EDitor!!
Not a "viitor".  Not a "emacsitor".  Those aren't even WORDS ED!
ED! ED IS THE STANDARD!!!

TEXT EDITOR.

When IBM, in its ever-present omnipotence, needed to base their
"edlin" on a UNIX standard, did they mimic vi?  No.  Emacs?  Surely
you jest.  They chose the most karmic editor of all.  The standard.


Thanks Rick
Now that I have succeeded in putting out my burning hair with a hammer;
and the true source of my suffering is revealed; terrible will be my 
vengence.:-)

regards Rohan McLeod

___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


Re: ed! the one true editor! (was Re: sed on a large file)

2022-12-11 Thread Rick Moen via luv-main
Quoting Craig Sanders (c...@taz.net.au):

> still useful) ed or ex. ed is the original unix text line editor, dating
> back to 1969 and still included with modern unix & linux systems.

It also famously had one of the most ultra-terse man pages in all of
Unix, thus leading to this humour piece (now arguably obsolete now that
Debian provided a rather more fleshed-out man page):



From: p...@athena.mit.edu (Patrick J. LoPresti)
Message-ID: <1991jul11.031731.9...@athena.mit.edu>
Sender: n...@athena.mit.edu (News system)
Subject: The True Path (long)
Date: 11 Jul 91 03:17:31 GMT
Path:
ai-lab!mintaka!olivea!samsung!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!patl
Newsgroups: alt.religion.emacs,alt.slack
Organization: Massachusetts Institute of Technology
Lines: 95
Xref: ai-lab alt.religion.emacs:244 alt.slack:1935

When I log into my Xenix system with my 110 baud teletype, both vi
*and* Emacs are just too damn slow.  They print useless messages like,
'C-h for help' and '"foo" File is read only'.  So I use the editor
that doesn't waste my VALUABLE time.

Ed, man!  !man ed

ED(1)   UNIX Programmer's ManualED(1)

NAME
 ed - text editor

SYNOPSIS
 ed [ - ] [ -x ] [ name ]
DESCRIPTION
 Ed is the standard text editor.
---

Computer Scientists love ed, not just because it comes first
alphabetically, but because it's the standard.  Everyone else loves ed
because it's ED!

"Ed is the standard text editor."

And ed doesn't waste space on my Timex Sinclair.  Just look:

-rwxr-xr-x  1 root  24 Oct 29  1929 /bin/ed
-rwxr-xr-t  4 root 1310720 Jan  1  1970 /usr/ucb/vi
-rwxr-xr-x  1 root  5.89824e37 Oct 22  1990 /usr/bin/emacs

Of course, on the system *I* administrate, vi is symlinked to ed.
Emacs has been replaced by a shell script which 1) Generates a syslog
message at level LOG_EMERG; 2) reduces the user's disk quota by 100K;
and 3) RUNS ED!!

"Ed is the standard text editor."

Let's look at a typical novice's session with the mighty ed:

golem> ed

?
help
?
?
?
quit
?
exit
?
bye
?
hello? 
?
eat flaming death
?
^C
?
^C
?
^D
?

---
Note the consistent user interface and error reportage.  Ed is
generous enough to flag errors, yet prudent enough not to overwhelm
the novice with verbosity.

"Ed is the standard text editor."

Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA!  ED HAS BEEN THE CHOICE OF EDUCATED
AND IGNORANT ALIKE FOR CENTURIES!  ED WILL NOT CORRUPT YOUR PRECIOUS
BODILY FLUIDS!!  ED IS THE STANDARD TEXT EDITOR!  ED MAKES THE SUN
SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless
help screens and cursor positioning code!  I just want an EDitor!!
Not a "viitor".  Not a "emacsitor".  Those aren't even WORDS ED!
ED! ED IS THE STANDARD!!!

TEXT EDITOR.

When IBM, in its ever-present omnipotence, needed to base their
"edlin" on a UNIX standard, did they mimic vi?  No.  Emacs?  Surely
you jest.  They chose the most karmic editor of all.  The standard.

Ed is for those who can *remember* what they are working on.  If you
are an idiot, you should use Emacs.  If you are an Emacs, you should
not be vi.  If you use ED, you are on THE PATH TO REDEMPTION.  THE
SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE
FAITHLESS.  DO NOT GIVE IN!!!  THE MIGHTY ED HAS SPOKEN!!!

?
___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au


ed! the one true editor! (was Re: sed on a large file)

2022-12-11 Thread Craig Sanders via luv-main
On Mon, Dec 12, 2022 at 12:35:11PM +1100, Jason White wrote:
> How would Perl (e.g., with -pi -e options) perform compared with Sed?

Like sed, perl creates a new file too but does it in a slightly different
way. IIRC, sed writes to a new file then renames it over the original, while
perl renames the original and then creates a new file with the original name
then deletes the renamed original file.  Different method, same basic result.

In most cases, the fact that it's a new file makes no difference. You will at
some point in the edit have two versions of the file on the disk at the same
time. IMO this is mostly irrelevant - if you don't have enough free space for
this then you have a much bigger problem to solve.

More significantly, however, the new file will have a new inode number which
will break any hard links (but not symbolic links) to that file if any exist.
As hard links aren't used all that often, this probably isn't a big deal
either...but it is definitely something you need to be aware of when using
perl or sed's -i options (and similar options in other programs).



If you want to do an actual in-place edit (with edits being performed on the
same file with the same inode), you could something like the ancient (but
still useful) ed or ex. ed is the original unix text line editor, dating
back to 1969 and still included with modern unix & linux systems. ex is
included with all versions of vi that I know of, including vim.  They're both
line-oriented text editors without fancy new-fangled stuff like a curses
visual interface.  They're very similar - ex is like a greatly enhanced
superset of ed. ex can do a lot more than ed: everything that vi or vim can do
except the "visual" stuff that only makes sense in a visual editor like vi.

e.g.

printf '%s\n' '/SET SQL/' i '-- ' . j w q | ed -s ./file.sql

or

printf '%s\n' '/SET SQL/' i '-- ' . j w q | ex ./file.sql

Here printf is used to pipe a series of commands into ed or ex (with a newline
character between each command):

 '/SET SQL/'   - regex search for line matching "SET SQL"
 i - insert text before current line
 '-- ' - the text to insert, two dashes and a space
 . - tells ed that input text is finished
 j - join the two lines ("-- " and "SET SQL...")
 w - write (i.e. save the edited file)
 q - quit

NOTE: ed/ex commands and input text which contain spaces, tabs, shell
metacharacters, etc will need to be quoted as usual.


Alternatively to just delete the line:

printf '%s\n' '/SET SQL/' d w q | ed -s ./file.sql

or

printf '%s\n' '/SET SQL/' d w q | ex ./file.sql


craig


PS: These programs are all related and share a common history. And they
all build upon a common set of basic editing commands. ex was an advanced
re-implementation of ed and vi was originally a visual mode for ex. and vim
is an enhanced re-implementation of vi.  Also, it's worth remembering that ed
is a **file** editor (as are ex and vi and vim), while sed was a **stream**
editor (nowadays, the -i option allows it to edit files too) - it modifies its
stdin and outputs to stdin.

The above is a gross simplification.  For a better and more detailed
simplification of the history, see:

https://en.wikipedia.org/wiki/Ed_(text_editor)
https://en.wikipedia.org/wiki/Sed
https://en.wikipedia.org/wiki/Ex_(text_editor)
https://en.wikipedia.org/wiki/Vi
https://en.wikipedia.org/wiki/Vim_(text_editor)


___
luv-main mailing list -- luv-main@luv.asn.au
To unsubscribe send an email to luv-main-le...@luv.asn.au