Replace Text in a File using the Command Line

This page answers questions like these:


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



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, string replace, in-place replace, inline replace, in-file replace, in-place text replace, inline text replace, in-file text replace, text substitution, perl, sed, linux, unix, solaris, bsd, aix

Copyright © HelpDoco.com
file-replace-text-in-place.txt
Linux-Unix/in-file-text-replace-using-perl-or-sed.htm
2