sed -i 's/search_string/replace_string/' filename
sudo nano file.text
sed -i -e 's/abc/XYZ/g' /tmp/file.txt
sed -i -e 's/search_string/replace_string/g' filename
# And with variables:
search_string="example"
replace_string="replacement"
file_name="filename.txt"
sed -i "s/$search_string/$replace_string/" $file_name
‘-i’ # option is used to modify the content of the original file
# with the replacement string if the search string exists in the file.
‘s’ # indicates the substitute command.
‘search_string’ # contains the string value that will be searched in the
# file for replacement.
‘replace_string’ # contains the string value that will be used to replace
# the content of the file that matches the ‘search_string’ value.
‘filename’ # contains the filename where the search and replace willbe applied.
# The ‘awk’ command is another way to replace the string in a file,
# but this command cannot update the original file directly like the ‘sed’ command.