!!!ED Editor

ed is the standard line oriented editor available on all Unix / Linux systems.  It also comes with Mac OS/X, and is available for Windows.

ed is a line oriented editor (as apposed to a screen oriented editor).  It requires no graphics and works on text one line at a time.

To evoke ed you use:  {{{ed myfile.txt}}}

Note, the stuff in the () below represents a range of lines to be operated on.  The stuff shown in the parenthesis is the default - what is used if you don't include an address range.  If you do include it, don't type the parenthesis with it. So, the parenthesis are used to indicate optional arguments in the list below.  It is never actually typed.


!!ed commands

!!Save and quit commands

|(1,$)w |			write (save) file
|(1,$)wq 	|		write and quit
|(1,$)w FILE|			write (save) to new file
|(1,$)wq FILE	|		write to new file and quit
|q|				quit
|Q|				quit - abort changes
|e FILE	|			edit new file (erase prior contents)
|E FILE	|			edit new file even of old file changed
|f FILE	|			change current file name to FILE
|($)r FILE|			read FILE into existing text

!!Displaying text

|(.,.)p	|			print lines
|(.,.)n	|			print lines with line numbers
|(.,.)l	|			list lines (display control characters)

!!Changing the current line

|.|				current line
|N|				goto line N
|$|				last line
|, or %	|			all lines
|.+1|				current line plus 1
|return	|			move to and display next line
|-|				previous line
|+N|				N'th next line
|-N|				N'th previous line
|;|				.,$
|/re/|				find regular expression
|//|				repeat last regular expression
|?re?|				search backwards
|(.)kX|				mark line as X (save position)
|'X|				the line marked as X (used anywhere a line number can be used)
|.=|				display current line number
|=|				display number of lines

ed's regular expression syntax corresponds to grep's basic regular expression syntax.  See [grep]


!!Changing text

|(.)a|				append text after current line (up to end input)
|(.)i|				insert text before current line (up to end input)
|(.,.)c	|			change (replace lines - delete & insert)
|(.,.)d	|			delete lines
|(.,.)s/re/replacement/	|	replace text (once per line)
|(.,.)s/re/replacement/g|		replace text (all per line)
|(.,.)s/re/replacement/N|		replace text (N'th occurrence per line - start at 1)
|(.,.)s	|			repeat last substitution
|.|				end input

!!Misc commands

|(.,.+1)j|			join addressed lines
|(.,.)m(.)|			move lines
|(.,.)t(.)|			copy (transfer) lines

!!Regular expressions

|.|				match any character
|\.|				match period
|x*|				match zero or more x's
|{{{[}}}xyz{{{]}}}|				character class - match x, y, or z
|{{{[}}}a-z{{{]}}}	|			match a through z
|{{{[}}}^xyz{{{]}}}	|			match anything except x, y, or z
|^abc|				match abc at the beginning of a line
|abc$	|			match abc at the end of a line
|{{{[}}}:alnum:{{{]}}}|
|{{{[}}}:alpha:{{{]}}}|
|{{{[}}}:cntrl:{{{]}}}|
|{{{[}}}:digit:{{{]}}}|
|{{{[}}}:lower:{{{]}}}|
|{{{[}}}:print:{{{]}}}|
|{{{[}}}:space:{{{]}}}|
|{{{[}}}:upper:{{{]}}}|

!!Advanced features

|(1,$)g/re/command-list	|	execute command-list for each matching line each command must be on its own separate line lines may be continued by ending them in \
|(1,$)G/re/|			interactively edit each matching line