/* BeejBlog */

SED – Insert text after match

General syntax:
  • sed “s/search-for-regex/& replace-with/” filename.txt
Example:
  • sed "s/BEGIN AS/& \n\nSET 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