Replace Text in a File

From KlavoWiki
Revision as of 06:09, 13 September 2011 by David (Sọ̀rọ̀ | contribs) (Created page with "To replace text in a single file or multiple files. <pre> sed -i 's/foo/foo-bar/g' 96??.cfg </pre> This will replace all the text that has foo with foo-bar in all files starting...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

To replace text in a single file or multiple files.

sed -i 's/foo/foo-bar/g' 96??.cfg

This will replace all the text that has foo with foo-bar in all files starting with 96 followed by any other 2 characters with a .cfg extension.

  • -i = tell sed to edit the file(s)
  • s = substitute the following text
  • foo = what you want to substitute
  • foo-bar = what you want to replace
  • g = global, match all occurrences in the line