SED PDA Reference Card SED, A Stream-oriented Editor [Condensed from: sed & awk Pocket Reference © 2000; by Arnold Robbins; ISBN: 1-56592729-X ] by Jesus Monroy, Jr. (didgood.com) NOTE: sed has two (2) internal buffers - "pattern space" (p-space) and "hold space" (h-space). Command-Line Syntax sed [-n] [-e] 'command' file(s) sed [-n] -f scriptfile file(s) Syntax of Commands general form: [addr[,addr]][!] cmd [arg] "addr" can be a line number, a symbol or a regular expression. "cmd" - commands as listed below. "arg" - apply only to certain commands (b, t, r, w & s). multi-command form: [/pattern/[,/pattern/]] [!]{ cmd1 cmd2 } Examples s/xx/yy/g subs. all lines (all occurrences) /BSD/d delete lines containing BSD /^BEGIN/,/^END/p print between BEGIN & END, incl. /SAVE/!d delete lines without SAVE /BEGIN/,/END/!s/xx/yy/g subs. all lines, except between Group Summary Basic editing a\ append after line c\ replace (usually block) i\ insert before line d delete s substitution y translate chars (like tr) Line information = line number l control chars (ASCII) p entire line(s) (or bound line) Input/output processing n output current, get next r read another file to p-space w write to another file q quit now! Yanking and putting h copy & overwrite h-space H copy & append h-space g get h-space & overwrite G get h-space & append x eXchange h-space & p-space Branching commands b branch to label or end t substitute, then branch :label label to branch to Multiline input processing N append next line to p-space D delete 1st part of p-space P print 1st part of p-space Alphabetic Summary # comment, except #n : label to branch to = line number a append after line b branch to label or end c replace (usually block) d delete D delete 1st part of p-space g get h-space & overwrite G get h-space & append h copy & overwrite h-space H copy & append h-space i insert before line l control chars (ASCII) n output current, get next N append next line to p-space p entire line(s) (or bound line) P print 1st part of p-space q quit now! r read another file to p-space s substitution t substitute, then branch w write to another file x eXchange h-space & p-space