Tuesday, October 20, 2009

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

1 comments:

  1. Sed in Spanish means thirsty.
    As in "Tengo sed. Vamos al beber." I'm thirsty. Let's go drinking.
    ReplyDelete