![]() Augeas has parsers that know about the file syntax (in this case, yum.repo syntax).There are several avantages to using Augeas vs sed/ awk: If you want to keep it in your bash script, you can pipe the commands into augtool: cat <<EOF | augtool If you want to modify several values, you can even use augtool as an interpreter: $ cat gtoolĭefvar epel /files/etc//epel.repo/epel The same goes for other values you may want to modify. ![]() If the priority key already exists, it will set its value, otherwise it will add a priority entry after the last entry in the section. Will set the priority of the epel repository to 10. Like ptman said, Augeas can save you from using sed/ awk: $ augtool -s set /files/etc//epel.repo/epel/priority 10 Like its listen = something, i want to modify it to listen = Quotes, don't know how it is done for bash sed '$a"Werulz, you are welcome"\'Īnother thing I need to modify a line in a conf but i don't remember Like "Thanks Quanta"(with quote) For php you put a \ with echoing Should be modified from Testing = "0" to Testing = "1"(with quotes) sed 's/Testing = "0"/Testing = "1"/g' Here for you: sed '/\/,/enabled=0/ ' remi.repoĪnother stuff i am not sure of:P I want to edit a file that has thisĪs Text Testing = "0"(Yes it has quotes and i need to keep it) It Modify all enabled=0 in that file, which will wreak the server.Can etc//remi.repo to change enabled=0 to enabled=1 under the One last suggestion I used sed -i 's/enabled=0/enabled=1/g' Worker_processes in that conf and replace text with worker_processesĤ sed '0,/worker_processes * /s//worker_processes 4 /' /etc/nginx/nf Now i want use sed to do the following 1.Find the FIRST occurrence of bak extension first): sed -i.bak '/enabled=1/a\priority=10' /etc//epel.repo Specify an in-place editing option ( -i) if you want (makes the backup with. Sed '/enabled=1/a\priority=10' /etc//epel.repo Like its listen = something, i want to modify it to listen = /tmp/php5-fpm.sock I need to modify a line in a conf but i don't remember what is the whole of text to replaced ![]() Testing = "0" to Testing = "1"(with quotes)Īlso i need to add some text with quotes at the end of a file with sedįor php you put a \ with echoing quotes, don't know how it is done for bash Testing = "0"(Yes it has quotes and i need to keep it) I want to edit a file that has this as Text However i have a feeling that it may modify all enabled=0 in that file, which will wreak the server.Can anyone suggest a better code. To change enabled =0 to enabled=1 under the section in remi.repo. Sed -i 's/enabled=0/enabled=1/g' /etc//remi.repo This is the most reliable method i though of when editing files (without nay risk of breaking any conf I want a sed command that find the FIRST wHOLE match case of the word worker_processes, delete line of text where the word is found and and paste worker_processes 4 there and then save file. Special Note Here: This is just an example. Lets suppose i want to modify nf using sedġ.Find the FIRST occurrence of worker_processes in that conf and replace text with worker_processes 4 I have successfully done most of the bash script I know its demanding but i need to create this for a friend who is noob at server management.Unfortunately i don't have time to study bash scripting from start as my exams as near.I will use your examples to write the script. Add some text to a file and save it(with nano).functions = to function = "text1","text2" My Question is how to do the 2 and 3rd part with bash script using nano (if possible, in case not possible then show me with sed)Īlso at some points i will have to modify variables in files Add a line priority=10 just after line enabled=1 in the epel sectionįor the first part i added yum install nano.I am a beginner in bash scripting.I want to create a bash script to install install and configure stuffs on my linux box in an automated way.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |