Skip to Content
Navigation:

A stick figure smiling

Here's a preview from my zine, Bite Size Command Line!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
read the transcript!

sed is most often used for replacing text in a file

$ sed s/cat/dog/g file.txt
“cat”can be a regular expression

change a file in place. with -i

person: in GNU sed it’s -i, in BSD sed, -i SUFFIX confuses me every time.

Some more sed incantations…

sed -n 12 p

print 12th line -n suppresses output so only what you print with ‘p’ gets printed

sed 5 d

delete 5th line

sed /cat/d

delete lines matching /cat/

sed -n 5,30 p

print lines 5-30

sed s+cat/+dog/+

(‘+’ can be any character)
Use + as a regex delimeter
person: way easier than escaping /s like s/cat\//dog\//!

sed -n s/cat/dog/p

only print changed lines.

sed G

double space a file (good for long error lines)

sed /cat la dog’

append ‘dog’ after lines containing ‘cat’

sed ‘i 17 panda”

insert “panda” on line 17

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)