Darkland | net

Sed Notes

Published on 29 July, 2020 by Amanda
Reference:https://unix.stackexchange.com/a/374128

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'
Where:
^ = start of line
\s* = zero or more whitespace characters
# = one hash mark
\([^!]\|$\) = followed by a character which is not ! or end of line.
Back