Replacing Text Inside a Huge File with sed

Replacing Text Inside a Huge File with sed

Opening a multi-gigabyte SQL dump in an editor to change a domain name is painful. sed edits the file in place without loading it all into memory.

The command

sed -i 's/findme/replacewithme/g' file.txt

The g flag replaces every match on each line. Make a copy first, and remember that serialised PHP data (common in WordPress databases) stores string lengths, so use a serialisation-aware tool for URL changes there.

Need a second pair of eyes on this? Our team handles server and automation work every week. See how we can help.

Keep reading

Related articles

All articles

Need a hand?

Stuck on something similar?
We can fix it with you.

Send us the problem. A senior developer reads every message and replies within one working day.