Sed Command Cheat Sheet

1 min read

Substitute text

sed 's/old/new/g'

Substitute text in line 10

sed '10s/old/new/g'

Find pattern in file and delete line

BSD / macOS only

sed -i '' '/pattern to match/d' ./infile

Find pattern in file and delete line with backup file

BSD / macOS only

sed -i.bak '/pattern to match/d' ./input.file

Source