Search notes:

sed example: Comment and add a line

The following script uses curly braces to execute multiple commands when an address has matched.
First, it comments the line reading rm a-file and then adds another line (rm another-file)
sed -e '/^rm a-file/ {
  s@^@# @;
  a rm another-file
}' testfiles/script
Github repository about-sed, path: /comment-and-add-line

Test file

This is the test file:
echo "This is a script"
sleep 1
rm a-file
sleep 1;
echo "script finished"
Github repository about-sed, path: /testfiles/script

See also

sed examples

Index