I want to edit manually my repo file from the command-line, preferably using sed. How can I do that based on the repo-name I want to edit?I want to search for a specific repo-name (example: reponame-2) and based on that change, for example, the option enabled=1 to enabled=0[repo-name1]name=repo-name1baseurl=http://linktomyrepo.comenabled=1sslverify=0proxy=_none_[repo-name2]name=repo-name2baseurl=http://linktomyrepo.comenabled=1sslverify=0proxy=_none_
edit repo file with sed
text processing;sed;repository
Perl's paragraph mode, where lines are defined by consecutive newlines, is perfect for this:$ perl -00pe 's/enabled=1/enabled=0/ if /\[repo-name1/' file [repo-name1]name=repo-name1baseurl=http://linktomyrepo.comenabled=0sslverify=0proxy=_none_[repo-name2]name=repo-name2baseurl=http://linktomyrepo.comenabled=1sslverify=0proxy=_none_Or, to edit the original file directly:perl -i -00pe 's/enabled=1/enabled=0/ if /\[repo-name1/' file Alternatively, you could use awk:$ awk -vRS='\n\n' -vORS='\n\n' '/\[repo-name1/{sub(/enabled=1/,enabled=0)}1;' file [repo-name1]name=repo-name1baseurl=http://linktomyrepo.comenabled=0sslverify=0proxy=_none_[repo-name2]name=repo-name2baseurl=http://linktomyrepo.comenabled=1sslverify=0proxy=_none_And, if you have a recent version of GNU-awk or any other awk suporting -i, you can do this to edit in place:awk -iinplace -vRS='\n\n' -vORS='\n\n' '/\[repo-name1/{sub(/enabled=1/,enabled=0)}1;' file Alternatively, to avoid the extra blank lines that the awk above adds to the end of the file, you could do something more complex like:$ awk -F= '/\[repo-name1/{a=1}/^\s*$/{a=0}a==1 && $1==enabled{$2=0}1;' file[repo-name1]name=repo-name1baseurl=http://linktomyrepo.comenabled 0sslverify=0proxy=_none_[repo-name2]name=repo-name2baseurl=http://linktomyrepo.comenabled=1sslverify=0proxy=_none_