ed – The Text Editor

 

ed is the standard UNIX text editor. It is available on all UNIX systems. ed works on a copy of the file. Each ed command is usually a single character, a letter.

Line number of a file in ed is given as 1,2,… The last line is obtained using ‘$’ and current line by ‘.’.

We can start ed editor using ed command followed by file name. If a file exists with the same name the editor will print the number of characters in the file including the new line character. If the file doesn’t exist, it will show a message showing no such file. We can start adding lines using the letter ‘a’. Now we can add the text to the file. To stop adding lines we have to type a ‘.’. To write the lines onto the file enter the letter ‘w’. Now the editor will show the number of characters in the file. To quit the editor we have to type the letter ‘q’. If we try to quit before writing the lines, ed will show a warning ‘?’. If we want to save the lines we can print the letter ‘w’, else quit by typing the letter ‘q’ again.

While in the editor, we can escape to the shell using ‘!’, ie without leaving the ed.

We can print the nth line by typing the command np or just the number n. Lines through m to n can be printed using the command m,np.

/pattern/ finds the next occurrence of pattern. ?pattern? to search backward.

To add a text after line n use the command na.

To insert text before line n use the command ni.

To delete lines m through n use the command m,nd.

To change lines m through n use the command m,nc.

The substitute command is s. s/old/new command replaces first old with new. s/old/new/g command replaces each old with new on the current line. s/old/new/gp command each old into new and print line.

To undo the recent substitution, use the command u.

To move lines m through n to after line d use the command m,nm d.

To copy lines m through n to after line d use the command m,nt d.

Advertisements

About Odol Shinu

I've completed my B Tech in Information Technology in 2010 from Government Engineering College Sreekrishnapuram Palakkad under Calicut University.

Posted on August 4, 2010, in GNU/Linux. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: