Darkland | net

Sed Notes

Published on 29 July, 2020 by Amanda

Replace text in file
sed -i '/pattern to match/new string' ./infile Example: $ sed -i 's/\/home\/amanda/'\$'HOME/g' ./Baldurs-Gate-Enhanced-Edition-Startup-Error-On-Linux-Mint-20.x.html
Delete lines in a file(s). In this example lines containing -- are deleted.
sed -i '/--.*/d' ./*
Regex Examples: sed -i -e '/^\s*#\([^!]\|$\)/d'
^ = start of line
\s* = zero or more whitespace characters
# = one hash mark
\([^!]\|$\) = followed by a character which is not ! or end of line.