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
delete lines matching /cat/
sed -n 5,30 p
print lines 5-30
(‘+’ 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.
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