Some New Ed Tips

<2025-02-07 Fri>

Ed does some things really well, despite its age.

Line numbers can be specified in different ways:

  • absolutely (1, 2, …)
  • by shorthand (e.g. $ for the last line and . for the current line)
  • by pattern searches or regex

DOT means two things in ed:

As above, dot can mean the current line. It can also mean "stop adding" in a different
context ( used after 'a')

Q quits absolutely

! lets you temporarily escape ed to type any shell command

!wc poem
.w !espeak — read current line aloud
1,2w !espeak — read lines 1-2 aloud.
%w !espeak — read whole file aloud

Note here w means 'write to standard output', not 'write to a file'!

Printing to standard output

1p
$p
1,3p

You can print a file a line at a time just by pressing RET.

You can go back up a line just by pressing MINUS.

You can also combine + and - with numbers as in

-2,$p — print the last three lines of a file

p, n and l will each give you something different

p prints lines

n prints lines with their numbers

l (list command) prints in a format that makes all characters in line visible. So for
example, one can see tab characters and the end of line character.

Search for things using patterns

/flea/ — search for next line containing flea
/flea/ — search for next occurrence after that
// — search for next using same pattern
?? — search for previous using same pattern

To break up long lines into shorter more manageable ones:

Replace a space with a newline character

s/text where break occurs/&\
/

Or to reformat the whole document:

!fold -s -w80 %

Return to Home