ed Line Editor

This handout describes a few simple commands of the Unix ed line editor. There are many more commands than are described here, and the commands here have additional options that are not described here.

To start the ed editor, issue the command ed <filename>, where <filename> is replaced by the name of the file you want to edit. The current line will be initialized to the last line of the file.

Some of the valid commands in ed are:

<enter>
Pressing the enter key moves the current line down one line.

p
Prints the current line.

np
Moves the current line to line n. (Replace n with a line number.)

w <filename>
Saves the current file. (Replace <filename> with the name of the file you want to save.)

q
Exits from ed.

e <filename>
Opens the given file. (Replace <filename> with the name of the file you want to edit.) Any changes that were made to the file that was being edited before will be lost if they were not saved.

d
Deletes the current line.

s/<old>/<new>
Find the characters <old> in the current line and replace them with the characters <new>. (Replace <old> and <new> with one or more characters.)

.c
<text>
.

Replace the current line with <text>. You can enter as many new lines as you want. When you are done entering new lines, enter a . on a line by itself. The new current line is the last new line entered.

.i
<text>
.

Insert new lines before the current line. You can enter as many new lines as you want. When you are done entering new lines, enter a . on a line by itself. The new current line is the last new line entered.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2001