![Forrest logo](/images/logo.png)
sed:tldr:d36c1
sed: Replace all `apple` (basic regex) occurrences with `mango` (basic regex) in a specific file and overwrite the original file in place.
$ sed -i 's/apple/mango/g' ${filename}
try on your machine
This command is using the sed
command in Linux/Unix to search and replace the word "apple" with "mango" in a file specified by the ${filename}
variable.
Let's break down the command:
sed
: This is the command for stream editor, which is used for text manipulation.-i
: This option tellssed
to perform an in-place edit, meaning it will modify the file directly rather than displaying the output on the terminal.'s/apple/mango/g'
: This is the search and replace expression. Thes/
indicates a substitution operation, andapple
is the word being searched for. It will be replaced withmango
. Theg
flag at the end means it will replace all occurrences of "apple", not just the first one it finds.${filename}
: This is a variable that holds the name of the file where the search and replace operation will be performed. You can replace${filename}
with the actual file name or provide it as an argument when executing the command.
Overall, this command will search for every occurrence of the word "apple" in the specified file and replace it with "mango", effectively performing a global search and replace operation.
This explanation was created by an AI. In most cases those are correct. But please always be careful and
never run a command you are not sure if it is safe.