Check out my first novel, midnight's simulacra!

Sed

From dankwiki
Revision as of 13:14, 23 August 2020 by Dank (talk | contribs) (→‎Join pairs of lines)
(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/ /' replaces every other newline with a space. Replace the space with whatever you want.