Linux replace command
About replace
The replace utility program changes strings in place in files or on the standard input.
Description
replace looks for all occurrences of string from and replaces it with string to. You can specify one or more pairs of strings to search/replace in a single replace command.
Use the -- option to indicate where the string-replacement list ends and the file names begin. In this case, any file named on the command line is modified in place, so you may want to make a copy of the original before converting it. replace prints a message indicating which of the input files actually got modifies.
If the -- option is not given, replace reads the standard input and writes to the standard output.
replace syntax
replace from to [from to] ... -- file_name [file_name] ...
replace from to [from to] ... < file_name
Options
| -?, -I | Display a help message and exit. |
| -#debug_options | Enable debugging. |
| -s | Silent mode. Print less information what the program does. |
| -v | Verbose mode. Print more information about what the program does. |
| -V | Display version information and exit. |
replace examples
Tip: The replace command is primarily used with msql2mysql although can still be used for a way to replace text within a file or input. If you are looking for a more advanced solution for replacing text within Linux we also suggest using the sed command.
replace "computer" "hope" -- example.txt
Replace the word computer with the word hope in example.txt, overwriting the original file with the changes.
Related commands
sed — A utility for filtering and transforming text.
