Sed Notes
Published on 29 July, 2020 by amjReference:https://unix.stackexchange.com/a/374128
This is valid for GNU sed 4.7
Replace text in file
sed -i 's/pattern to match/new string/g' ./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'
Where: ^ = start of line \s* = zero or more whitespace characters # = one hash mark \([^!]\|$\) = followed by a character which is not ! or end of line.