HOWTO: The famous Mister Ed

Forum rules
Share your brain ;)
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

HOWTO: The famous Mister Ed

Unread post by machinebacon » Mon Oct 28, 2013 5:11 am

[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.
..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: HOWTO: The famous Mister Ed

Unread post by rhowaldt » Mon Oct 28, 2013 9:19 am

cool! thanks :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: HOWTO: The famous Mister Ed

Unread post by dkeg » Mon Oct 28, 2013 1:16 pm

Haha, that is pretty cool mb. almost like ability to take a quick note at any time, without extra overhead. Nice HowTo

Work hard; Complain less

User avatar
DebianJoe
Frame Buffer
Posts: 1915
Joined: Mon Jul 01, 2013 5:41 am
Location: emacs.d

Re: HOWTO: The famous Mister Ed

Unread post by DebianJoe » Mon Oct 28, 2013 2:14 pm

http://www.gnu.org/fun/jokes/ed-msg.txt

....even I think that ed is too minimal.
|>>BBQ Roaster, Alpha Branch<< | >> clinky << | >> X11 must die << |
Thanks BASIC

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: HOWTO: The famous Mister Ed

Unread post by rhowaldt » Mon Oct 28, 2013 2:30 pm

^ lol :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
z3bra
Window Manager
Posts: 53
Joined: Fri Jun 27, 2014 8:34 am
Location: France
Contact:

Re: HOWTO: The famous Mister Ed

Unread post by z3bra » Wed Sep 03, 2014 8:55 am

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 ;)
BANGARANG, MOTHERFUCKER.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: HOWTO: The famous Mister Ed

Unread post by machinebacon » Wed Sep 03, 2014 9:22 am

Thanks for the bump ;)
..gnutella..

Post Reply