How to add a # before any line containing a matching pattern in BASH?

The following sed command will work for you, which does not require any capture groups:

sed /000/s/^/#/

Explanation:

  • /000/ matches a line with 000
  • s perform a substitution on the lines matched above
  • The substitution will insert a pound character (#) at the beginning of the line (^)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)