Page 1 of 1

HOWTO: The famous Mister Ed

Posted: Mon Oct 28, 2013 5:11 am
by machinebacon
[yt]y_PZPpWTRTU[/yt]

The GNU line editor. It can save some serious ass. Let's create a file, save it, edit it, move stuff around.

Starting 'ed'

ed is not always included, so you might wat to install it. Have a try, in your terminal, enter

Code: Select all

ed
Ed is now waiting for input, this is the command mode. Not quite obvious? Let's change the prompt:

Code: Select all

P
which brings up an asterisk as prompt. In the future you can start ed, showing a prompt like "Ready:" the next time using ed -p Ready:

Creating a new file

Creating a new file happens by appending lines to the existing file (which is of course not existing yet), so let's append:

Code: Select all

a
and start to type. Hitting enter bring the newline, and we stay in append mode. When you finished, hit Enter and type a period. That's how it looks like from the start to here:

Code: Select all

bbq@grill $ ed
P
*a
This is line 1
And this is line 2
This is the last line.        
.
*
Remember, the asterisk is our command prompt, so now ed is waiting for input.

Save and Quit

Let's just imagine we want to write this file to disk and then quit (much like :wq) - save it as 'pensi.txt'

Code: Select all

w pensi.txt
and let's quit:

Code: Select all

q
If we enter a

Code: Select all

Q
it is similar to vi's :q! - an unconditional quit: all changes are lost.

Tomorrow: edit an existing file, search and replace.

Re: HOWTO: The famous Mister Ed

Posted: Mon Oct 28, 2013 9:19 am
by rhowaldt
cool! thanks :)

Re: HOWTO: The famous Mister Ed

Posted: Mon Oct 28, 2013 1:16 pm
by dkeg
Haha, that is pretty cool mb. almost like ability to take a quick note at any time, without extra overhead. Nice HowTo

Re: HOWTO: The famous Mister Ed

Posted: Mon Oct 28, 2013 2:14 pm
by DebianJoe
http://www.gnu.org/fun/jokes/ed-msg.txt

....even I think that ed is too minimal.

Re: HOWTO: The famous Mister Ed

Posted: Mon Oct 28, 2013 2:30 pm
by rhowaldt
^ lol :)

Re: HOWTO: The famous Mister Ed

Posted: Wed Sep 03, 2014 8:55 am
by z3bra
Bringing this thread back up, because ed is a fine tools I like to use from time to time (read: when vim takes about 2 seconds to go down one line, because of a shitty laggy connection).

There are many useful trick one should be aware of when using ed. The first one is that you can use external tools:

Code: Select all

~$ ed
i
Content of directory ~/etc
.
r !ls ~/etc
186
Q
ed also has a builtin sed-like substitution engine:

Code: Select all

~$ ed
i
This is a shitty sentence
.
s/tt/n/
This is a shiny sentence
Q
And then, here are a few handy commands worth knowing:

Code: Select all

,p : print the whole file (shortcut to "1,$p", similar to "%" in vi)
.n  : print the current line number along with the line itself
g/re/p : search for the regular expression "re" and print those lines (does it looks familiar ?)
s/e/d: replace expression "e" by expression "d" (wait... I know this, too !)
2m$ : move line 2 to the end of the file
I can't encourage Vim users enough to give ed a try. You'll get WAY MORE proficient at Vim after a week using only ed (even a single day should be fine !)
After all, vi was only the visual mode of ed ;)

Re: HOWTO: The famous Mister Ed

Posted: Wed Sep 03, 2014 9:22 am
by machinebacon
Thanks for the bump ;)