Replace Text in a File

From KlavoWiki
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