Linux and Unix replace command

Quick links

About replace
Syntax
Examples
Related commands
Linux and Unix main page

About replace

The replace utility program changes strings in place in files or on the standard input.

Syntax

replace from to [from to] ... -- file_name [file_name] ...
replace from to [from to] ... < file_name

from represents a string to look for and to represents its replacement. There can be one or more pairs of strings.
--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 it actually modifies.

If the -- option is not given, replace reads the standard input and writes to the standard output.
-?, -I Display a help message and exit.
-#debug_options Enable debugging.
-sSilent 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.

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're looking for a more advanced solution for replacing test within Linux we also suggest using the sed command.

replace "computer" "hope" -- example.txt

Replace the word 'computer' with the word 'hope' in the example.txt file.

Related commands

sed