ED(oh) LOCAL ED(oh) ed - text editor: usage TOC COMMANDS - general - address - print - edit - marks - files - searching - interactive_edit - important - shell_commands SPLIT_LINES SCRIPTING - example SEE ALSO NOTE: this document is based on OpenBSD ed, there may be some differences on GNU ed. COMMAND LINE -p | specify prompt. Eg.: -p: COMMANDS [range]command general P | toggle prompt. q | quit. Warns if the buffer has been modified. Q | quit regardless of whether any changes have been made to the buffer. h | explain last error. H | toggle error explanation. u | undoes the last command. = | print total lines. address Most commands require a range on which to be executed. If no range is specified, it defaults to the current range. Exceptions: u (undo), z (scroll), h (help messages). n : 6 n,n : 4,5 + : next line. - : previous line. . : current line. $ : last line. +n : address at n lines after current line. -n : address at n lines before current line. ; : from current line to the end. /pattern/ : next line matching pattern. // repeats last search. ?pattern? : previous line matching pattern. ?? repeats last search. print p : print addressed lines. n : print addressed lines with line numbers. l : print addressed lines including control and non-printable characters. edit a : append: start adding text after the range. (Eg.: 4a) i : insert: start adding text before range. (Eg.: 4i) c : change: change the addressed line. (Eg.: 4c) d : delete: deletes range. (Eg.: 4d) m : move: move source range after target range. (Eg.: 4m5) t : copy (transfer): copy source range after target range. (Eg.: 4t6) j : join: join addressed lines. (Eg.: 4,5j) marks kl : mark an range with a lower-case letter. (Eg.: 4ka) 'l : set current range to the range marked as l. (Eg.: 'a > will set current range to 4) files e [filename] : edit file, if no file is specified it reloads the current file. E : same as e but discards changes if any. w [file] : writes file. If file is not specified, it writes the current file. [range]w [file] : writes specified range to file or current file if no file is specified. [range]W [file] : same as w but appends to filename if the file exists. % : represents the current file. f : sets/shows the current filename. r [file] : reads file into buffer at the end. [range]r [file] : reads file into buffer after range. searching g : search globally for matches. v : search globally for non-matching lines. interactive_edit 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 important s : normally, substitution is called with /pattern/, but any character can be used (Eg.: |pattern| or @pattern@). this is useful when substituting paths or variables. z[n] : scroll. - if n is specified, scroll the number of lines specified by n. - If n is not specified and zn has been run before, remember the number of lines used before. - if n is not specified and zn has not been run before, scroll the number of lines determined by the terminal size. - n: add n to show line numbers. (Eg.: z5n) shell_commands 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 SPLIT_LINES $ ed t a hello bye . w 10 w !awk 'sub("o ","o\n",$0);' > % e 10 ,n hello bye SCRIPTING NOTE: It's important to always have the . and w on any interactive commands. To add a . on a script without ending the input, enter \. and then substitute the \ : ,s@^\\.$@.@ example $ 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 SEE ALSO - OpenBSD manpages: ed(1) links - Solene - ed split lines: https://dataswamp.org/~solene/2018-12-04-fun-splitting-line.html - Linux port - OpenBSD ed at GitHub: https://github.com/ibara/oed - GNU ed: https://www.gnu.org/software/ed/ed.html - sam - multi-file text editor: http://sam.cat-v.org/ - Edbrowse, a Command Line Editor Browser: https://edbrowse.org/ - man.cat-v ed(1) - Unix First Edition Manual Page: http://man.cat-v.org/unix-1st/1/ed - https://www.gnu.org/software/diffutils/manual/html_node/Detailed-ed.html GNUed Detailed ed (Comparing and Merging Files) - Example ed (Comparing and Merging Files): https://www.gnu.org/software/diffutils/manual/html_node/Example-ed.html - ed Scripts (Comparing and Merging Files): https://www.gnu.org/software/diffutils/manual/html_node/ed-Scripts.html - unix.com - Ed command execution in script file: https://www.unix.com/shell-programming-and-scripting/233897-ed-command-execution-script-file.html AUTHORS ohazot(oh) | about(oh) | ohazot.com: https://ohazot.com OpenBSD 7.8 , linux | Created:2025-10-03|Updated:2025-11-27| ED(oh)