sed

Manipulation

Replace text in a file

28-06-2023, source: self + My Shitty Code

sed -i '' 's/text_to_be_replaced/replacement_text/' /Users/user/file.txt
  • -i edits files in-place, saving backups with the specified extension. If a zero-length extension is given, no backup will be saved. Unlike -I, each file is treated independently from other files.

  • Important: In MacOS, the extension argument must be explicitly given (-i '' instead of -i).