im newb in scripting\programming. I'm writing a script that will change parameters in configuration file and then start the daemon. I have a problem with paste variable content (string) into a specific position of file. There is 'username' word in that file by default and i has defined specific username into variable, how i can replace that 'username' with variable content? Please give me advice.
Asked
Active
Viewed 433 times
0
-
3Something like `sed -i 's/username/new_user_name/' daemon.conf`. Option `-i` is for _inplace replacement_ so you don't have to write a new file and then rename it. Be careful though, this option is not always available. Check it by reading the manual : `man sed`. – maxime.bochon Oct 21 '16 at 07:52
-
How i can select line number and character position in string using sed? – N. Artem Oct 21 '16 at 08:25
-
Why do you need to select the line number in your specific case ? In the script @maxime.bochon gave you, `sed` will automatically locate the word `username` and replace it with `new_user_name` – Aserre Oct 21 '16 at 08:41
-
Thank you, it worked with username. But now i have problem with password substitution, because there is several **password** keyword instances in a file. So command like **sed -i 's/password/$UsrPass/'
**, replace all instances. How i could replace only one word? – N. Artem Oct 21 '16 at 10:27