_                    _
  ___ | |__   __ _ _______ | |_
 / _ \| '_ \ / _` |_  / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
 \___/|_| |_|\__,_/___\___/ \__|

ed_examplesinteractive edit, scripting and tips

Commands G and V work the same as the lower case version, but edits each match interactively.

  1. G/re/
  2. Returns the first match.
  3. User edits the match.
  4. ed displays the next match.
  5. The user can edit the match or enter & to repeat the last non-empty command list.
$ ed -p :
:a
line 1
line 2
line 3
.
:G/l/
line 1
s/n/a/
line 2
s/e/o/
line 3
&
:,n
liae 1
lino 2
lino 3

The following commands can be used with shell commands:

e : edit output of command : e !command
r : read output of command into buffer : [range]r !command
w : write addressed lines into command. : [range]w !command
$ ed -p :
:e !ls
:,n
dir1
dir2
:r !ls dir1
:,n
dir1
dir2
file1
:w !xargs -n1 echo
dir1
dir2
file1

$ ed t
a
hello bye
.
w
10
w !awk 'sub("o ","o\n",$0);' > %
e
10
,n
hello
bye

NOTE: It's important to always have the. and w on any interactive commands.
  To add a . on a script without ending the input, one option is to enter \. and then substitute the \ : ,s@^\\.$@.@

$ ed script
a
a
this line is appended
\.
w
.
,s@^\\.$@.@
w
q
$ cat script
a
this line is appended
.
w
$ cat test.txt
line 1
$ ed - test.txt < script
$ cat test.txt
line 1
this line is appended

(back to top)

- Translate to Spanish.

(back to top)

ed
- Solene - ed split lines
- Example ed (Comparing and Merging Files)
- ed Scripts (Comparing and Merging Files)
- unix.com - Ed command execution in script file

(back to top)

2026-06-02 : Created.

(back to top)

ohazot | about | ohazot.com <admin@ohazot.com>

OpenBSD 7.9 2026-06-02