Ask Your Question
0

How can you use Linux shell bash to execute a sed command that replaces content in a file and saves the changes?

asked 2021-10-20 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-09-11 13:00:00 +0000

huitzilopochtli gravatar image

You can use the following command in Linux shell bash to execute sed command that replaces content in a file and saves the changes:

sed -i 's/old-text/new-text/g' file.txt

In this command:

  • -i flag is used to save the changes in the file.
  • s is the substitution command in sed.
  • old-text is the text that you want to replace.
  • new-text is the replacement text.
  • g flag tells sed to replace all occurrences of the old-text in the file.

Replace file.txt with the name of the file in which you want to make the changes. Make sure you have the permission to modify the file.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-20 11:00:00 +0000

Seen: 8 times

Last updated: Sep 11 '21