# Ever used the famous ed?



## Spartrekus (Apr 28, 2019)

Good morning,

Have you ever used the famous ed?

It is still widely used today. 


```
ED(1)                   FreeBSD General Commands Manual                  ED(1)

NAME
     ed, red – text editor

SYNOPSIS
     ed [-] [-s] [-p string] [file]
     red [-] [-s] [-p string] [file]

DESCRIPTION
     The ed utility is a line-oriented text editor.  It is used to create,
     display, modify and otherwise manipulate text files.  When invoked as
     red, the editor runs in "restricted" mode, in which the only difference
     is that the editor restricts the use of filenames which start with ‘!’
     (interpreted as shell commands by ed) or contain a ‘/’.  Note that
     editing outside of the current directory is only prohibited if the user
     does not have write access to the current directory.  If a user has write
     access to the current directory, then symbolic links can be created in
     the current directory, in which case red will not stop the user from
     editing the file that the symbolic link points to.
```


----------



## ralphbsz (Apr 28, 2019)

I've never heard of anyone actually using a line-based editor in the last 20 years or so.  Since the advent of inexpensive terminals with character-addressable IO, this has simply not been necessary (which means roughly since the time of the Hazeltine or VT52.    And editing in line mode is slow and painful.  The only time I've had to do is: either on very small microprocessor-based development systems (like an 8080 with 16kB of memory), or on early IBM 370 machines before XEDIT or similar TSO editors such as NEWLIB become widespread.

I started using Unix in the mid-1980s (maybe 87 or so), and at that point vi and emacs were already universally available (although I'm not sure that the emacs we used back than was already GNU emacs; it might have been the TECO-derived emacs).

I would disagree with "still widely used".  There are some old-timers who use ed in scripts (with canned editing commands), but other than that it has fallen by the wayside.


----------



## Spartrekus (Apr 28, 2019)

ralphbsz said:


> I've never heard of anyone actually using a line-based editor in the last 20 years or so.  Since the advent of inexpensive terminals with character-addressable IO, this has simply not been necessary (which means roughly since the time of the Hazeltine or VT52.    And editing in line mode is slow and painful.  The only time I've had to do is: either on very small microprocessor-based development systems (like an 8080 with 16kB of memory), or on early IBM 370 machines before XEDIT or similar TSO editors such as NEWLIB become widespread.
> 
> I started using Unix in the mid-1980s (maybe 87 or so), and at that point vi and emacs were already universally available (although I'm not sure that the emacs we used back than was already GNU emacs; it might have been the TECO-derived emacs).
> 
> I would disagree with "still widely used".  There are some old-timers who use ed in scripts (with canned editing commands), but other than that it has fallen by the wayside.



widely - relatively widely.
ed is useful sometimes, since it is there, we use it sometimes.


----------



## drhowarddrfine (Apr 28, 2019)

vi is there always so we use vi always. 
I used ed once, sometime between 1981 and 1985, while writing assembly for a 6805 processor for a vending machine. Something broke somewhere and we couldn't use whatever our regular editor was. I don't remember any details beyond that.

Why are you asking this reddit-like question that I doubt anyone cares about? (Which is the basis for most questions on reddit.)


----------



## hruodr (Apr 28, 2019)

ralphbsz said:


> There are some old-timers who use ed in scripts (with canned editing commands), but other than that it has fallen by the wayside.



I do not understand what do you mean with old timers. It is very usefull in scripts and not a replacement of `sed`.


----------



## aragats (Apr 28, 2019)

hruodr said:


> It is very usefull in scripts and not a replacement of  sed.


Do you mean "`sed` is not replacement of `ed` in scripts?" I can't imagine why. Would you bring an example?


----------



## hruodr (Apr 28, 2019)

aragats said:


> Would you bring an example?



How do you delete the last two lines of a file with `sed`?


----------



## Spartrekus (Apr 28, 2019)

hruodr said:


> How do you delete the last two lines of a file with `sed`?


Good one.

aragats: I prefer to use ed rather than vi.


----------



## aragats (Apr 28, 2019)

hruodr said:


> How do you delete the last two lines of a file with  sed?


`sed '$!N;$D' myfile`



Spartrekus said:


> I prefer to use ed rather than vi.


Depending on what you're doing you may change your preferences.


----------



## hruodr (Apr 28, 2019)

Editing with tricks (as far as possible) will substitute a comfortable use of `ed`?


----------



## aragats (Apr 28, 2019)

hruodr said:


> Editing with tricks will substitute a comfortable use of  ed?


By no means I tried depreciating ed's value. It's great if you're comfortable with it, otherwise a work can be still done with other tools too.
In other words, rephrasing ralphbsz 's comment above, it's not widely used since not many people know it "fluently".


----------



## linux->bsd (Apr 28, 2019)

Was forced to use `ed` once while upgrading a Linux system that failed in an ambiguous state. Tried all the usual editors, but none of them would run. That was a pain.


----------



## Spartrekus (Apr 29, 2019)

linux->bsd said:


> Was forced to use `ed` once while upgrading a Linux system that failed in an ambiguous state. Tried all the usual editors, but none of them would run. That was a pain.



First learning experience on Unix should be ed, awk, bc,... and later vi, emacs, ...
Then, C and to end with GO and Java  Born, live and die with Java


----------



## linux->bsd (Apr 30, 2019)

Spartrekus said:


> First learning experience on Unix should be ed, awk, bc,... and later vi, emacs, ...



My mistake -- I didn't realize I was speaking with a crazy person. 

I think new *nix users should strive to maximize their productivity by learning easy enough programs to get things done, and gradually learn more difficult -- more powerful -- programs. Sadly, most users instead choose to stick with programs they know instead of growing, and do things very inefficiently for the rest of their lives.


----------



## Spartrekus (Apr 30, 2019)

linux->bsd said:


> My mistake -- I didn't realize I was speaking with a crazy person.
> 
> I think new *nix users should strive to maximize their productivity by learning easy enough programs to get things done, and gradually learn more difficult -- more powerful -- programs. Sadly, most users instead choose to stick with programs they know instead of growing, and do things very inefficiently for the rest of their lives.



It is not necessary to use BSD like a Microsoft Windows machine, with minimal functionalities, but you are free to do so


----------



## zirias@ (Apr 30, 2019)

That's crazy talk. There's nothing you can do with ed that you can't do with vi (for interactive use) and all vi needs is a terminal with screen control. So why ever use ed as long as you're not on an incredibly ancient terminal or completely broke your system, so vi won't run any more?

Using vi is not "minimal functionalities", using ed most certainly is.

BTW, talking about Microsoft, they had their own EDLIN, which they retired a long time ago. Well, EDLIN was inferior to ed, and EDIT or notepad is far inferior to vi, or gvim, or emacs ... but it's the same evolutionary step, from line-based to full-screen.


----------



## Nicola Mingotti (Apr 30, 2019)

I used ed a few times. Of course there are much more practical and excedingly more sophisticated editors. 

Usually I use Emacs, very often in Tramp mode. If it is not available or I just need to edit 3 short files in a system, then i do it in vi, i do not install Emacs. I would appreciate if FreeBSD had mg in the base, as OpenBSD does, but that is another story.

A few times it happened to me the terminal was so bad i had to use ed. This happened mostly in embedded systems, AFAIRemember, on serial lines.

I found recently that ed can be a nice solution if you want to copy part of your console to a file. Well, a substitute for 

> echo "lorem ipsum ..." > thefile.txt

because it runs on a few lines and still let you see most of the console.


----------



## Spartrekus (Apr 30, 2019)

Nicola Mingotti said:


> I used ed a few times. Of course there are much more practical and excedingly more sophisticated editors.
> 
> Usually I use Emacs, very often in Tramp mode. If it is not available or I just need to edit 3 short files in a system, then i do it in vi, i do not install Emacs. I would appreciate if FreeBSD had mg in the base, as OpenBSD does, but that is another story.
> 
> ...



Knowledge.

_ed_ was well known to be powerful. Today, maybe, it needs to be rediscovered to know what it can.
there are many cool manuals on the web how to use _ed_.

In all cases, _ed_ is much faster and efficient than vi or vim for editing line contents and also entering new text for large files or distant. Because software running distant are slow and bloated, wasting machine performances and networks, _ed_ may get a revive.

@fromLinux2Unix:
People can prefer original osh, or zsh or ... a slow bash, ... or kde    (... or Android to get full zero power  ).


----------



## gpw928 (May 1, 2019)

Spartrekus said:


> Have you ever used the famous ed?


Certainly, along with a DEC LA120, attached to a VAX 750, as the console.  

Once you have conquered ed(1), the power and the glory of regular expressions is mastered, as is  sed(1), the best bits of perl(1), line editing mode in vi(1), not to mention history management in a number of shells.  I do not believe that there is any other sensible route to competence in the Unix command line (emacs  affectionadios may haggle at the fringes).

No child should be allowed a screen editor until they have mastered ed(1)!


----------



## Spartrekus (May 1, 2019)

gpw928 said:


> Certainly, along with a DEC LA120, attached to a VAX 750, as the console.
> 
> ....
> 
> No child should be allowed a screen editor until they have mastered ed(1)!



I was sure that I could read this ...


----------

