SED – Insert text after match

By Beej

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
Share: Twitter Facebook LinkedIn