Bash and Linux 5 · Searching and text
Replace text in a file
Replace every occurrence of a word in place.
sed -i 's/old/new/g' file.txt
Caution: -i edits the file in place. On macOS use sed -i '' instead. Test without -i first.
Official Bash and Linux 5 documentation
More searching and text commands
- Search file contents
- Find files by name
- Find files changed recently
- Count lines
- Count duplicate lines
- Print one column
All searching and text commands · Bash and Linux 5 cheatsheet