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 replace/insert my own settings in that value.
相关问题
- How to get the return code of a shell script in lu
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Invoking Mirth Connect CLI with Powershell script
- Error building gcc 4.8.3 from source: libstdc++.so
You can use sed to do this:
sed is probably available on every unix like system out there. If you want to replace more than one occurence you can add a g to the s-command:
Be careful since this can completely destroy your configfile if you don't specify your toreplace-value correctly. sed also supports regular expressions in searching and replacing.
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:
If you don't specify an output, the replacement will go to stdout.
Look at the UNIX power tools awk, sed, grep and in-place edit of files with Perl.
Generally a tool like awk or sed are used for this.