SED – Insert text after match

General syntax:

  • sed “s/search-for-regex/& replace-with/” filename.txt

Example:

  • sed “s/BEGIN AS/& nnSET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED/” Plans_s.sql

Explanation:

  • s/search-for-regex/replace-with/ = search and replace command
  • & = the matched text (effectively leaves the matched text alone rather than “replacing” it)
  • n = carriage return
  • Sed in Spanish means thirsty.
    As in "Tengo sed. Vamos al beber." I'm thirsty. Let's go drinking.