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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758200332, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/sed/examples/comment-and-add-line(62): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78