3 ms·
This is timely - I wrote an ed guide today and this post is a good opportunity to share it. I've been working on a remote server via ILO-in-a-browser with broke
by cturner 17y ago
This is timely - I wrote an ed guide today and this post is a good opportunity to share it. I've been working on a remote server via ILO-in-a-browser with broken console definitions and a screen that's too small for the interface. It's a gift - I've wanted to be fluent in ed for a long time and spent the time to get there today.
If anyone has something similar for console-mode sam usage I'd love to know that too.
Anyway - the guide:
Ed doesn't push any of the fancy cruft that modern
editors do - full screen views of the text in question
or fiddly mouse interfaces.
It is line based, scriptable, it works *everywhere*
that unix runs, and the default configuration is
predictable. A true power tool from the days of yore
when men were men and each tool did one simple thing
extremely well.
How to get into ed and create some text:
<pre>
$ touch my_filename
$ ed my_filename
0
a
Here is some text
next line
more
yet more
The dot on the next line indicates I'm done inserting text. Then save and exit.
.
w
q
$
</pre>
Basic commands:
* a: append to the first line
* p: print the current line
* n: print the current line with a line number (handy)
* %n: list all lines
* 1n: list line one
* 1,5n: line lines one to five
* 5,$n: list lines five until the end
* 2d: delete line two
* 3,4j: merge lines 3 and 4
* 2i: insert text to a new line before the current line 2
* P: enable prompt
* %l: - that's a lower-case letter after 'k' not the
number one. Print all lines, including end-of-line
markers (useful in dos2unix settings among others).
Regular expressions (this is where it gets exciting):
* 2s/next/another/: change the word 'next' on line
two do 'another' (don't forget that trailing slash)
* g/e/: find all the lines containing the letter 'e'
* g/e/n: find all the lines containing the letter 'e'
and then print them out with their line number next
to them.
* %s/e/q/: change the first instance of the letter 'e'
to 'q' on all lines
* %s/e/q/g: change all instances of the letter 'e' to
'q' on all lines
* 1,5s/e/q/3: change the third instance of the letter
'e' to 'q' on all lines
* %v/for/n: print out the lines that do NOT contain
the word 'for'
Other magic:
* 1,4y: cut ('yank') lines 1 to 4
* 5x: paste to after line 5
* 1,3t6: Transfers lines one to three to a position
after line 6.
- uriel 17y agoEd is still one of the greatest text editors around, I still use it rather often for short edits.