Search and replace in a file without opening it

Occasionally I'll need to perform a search and replace in a file so large that I can't reasonably open it in Vim. Using Perl has performed well for me in cases like this:
perl -pi -e 's/toFind/toReplaceWith/g' filePath
For example, sometimes I need to change the names of scaffolds in a large SAM file:
perl -pi -e 's/chromosome_//g' ./example.sam

Comments