Find and replace in shell scripting

前端 未结 7 2124
暖寄归人
暖寄归人 2021-02-01 09:20

Is it possible to search in a file using shell and then replace a value? When I install a service I would like to be able to search out a variable in a config file and then repl

7条回答
  •  别那么骄傲
    2021-02-01 09:56

    You can use sed to perform search/replace. I usually do this from a bash shell script, and move the original file containing values to be substituted to a new name, and run sed writing the output to my original file name like this:

    #!/bin/bash
    mv myfile.txt myfile.txt.in
    
    sed -e 's/PatternToBeReplaced/Replacement/g' myfile.txt.in > myfile.txt.
    

    If you don't specify an output, the replacement will go to stdout.

提交回复
热议问题