Check out my first novel, midnight's simulacra!

Sed

From dankwiki
Revision as of 12:56, 23 August 2020 by Dank (talk | contribs) (Created page with "The '''s'''tream '''ed'''itor. Sometimes the '''s'''hitty '''ed'''itor. <tt>sed</tt> works on lines at a time (mostly). Note that GNU and POSIX <tt>sed</tt> differ in some sig...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The stream editor. Sometimes the shitty editor. sed works on lines at a time (mostly). Note that GNU and POSIX sed differ in some significant ways.

Use -i to run sed on a file inline. Never use e.g. cat file | sed > file; the shell redirection is going to open file for writing with truncation, which is probably not what you want. Supply expressions on the command line with -e, and/or files of expressions with -f.

Recipes

Join pairs of lines

sed 'N;s/\n/,/'