Replace Text in a File using the Command Line

This page answers questions like these:

Replacing Text using Perl:

perl -p -i[EXTENSION] -e 's/FROM/TO/g' FILE ... Example:
perl -p -i.bak -e 's/YES/NO/g' file1 file2

Replacing Text using Sed:

sed -i[EXTENSION] [--follow-symlinks] 's/FROM/TO/g' FILE ...



Related Links:
Count Occurrences of a Hexadecimal Sequence in a File
Count Occurrences of a String in a File
Find Positions of a Hexadecimal Sequence in a File
Join Lines of Text File Together
Output Lines of a File in Reverse Order
Output the Lines Between Two Matching Lines
Sed Cannot Rename Temporary File Permission Denied

Home  >  Linux / Unix  >  Replace Text in a File using the Command Line


Tags: text replace, in-place replace, in-line replace, in-file replace, in-place text replace, in-line text replace, in-file text replace, text substitution, perl, sed, linux, unix, solaris, bsd, aix

Src: file-replace-text-in-place.txt
Dst: Linux-Unix/in-file-text-replace-using-perl-or-sed.htm
Ads: 3