Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm installing the Epel repo via a shell script, the repo comes by default disabled, I would like to enable it so the script can install further packages.

The following install the Epel repo:

yum install -y epel-release

This will create /etc/yum.repos.d/epel.repo, which contains:

[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

Now, I want to enable only the first repo '[epel]. I tried with sed but so far only managed to enable all of them (I'm a sed beginner):

sh-3.2$ sed 's,enabled=0,enabled=1,g;' ./epel.repo
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

This version of the command will not change anything:

sed 's,\(\[epel\].*\)enabled=0,\1enabled=1,;' ./epel.repo

What is the regex that will work for me? Or is there a better way to do this?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

sed(1) doesn't edit the file in place, it sends the edits to its output. To edit in-place you need to give the -i (or --in-place) flag. Also, what you are doing is to edit lines that contain [epel].*enabled, which you just won't find. You want to limit the replacement to the section starting [epel], which ends with the next [:

sed -i -e '/\[epel\]/,/^\[/s/enabled=0/enabled=1/' ./epel.repo
share|improve this answer
    
Thanks. I actually knew it wasn't editing in place, I just copy pasted my test but was planning to use an output redirect in the final version. The -i flag is handy. It took some time to understand what your example was doing, for those trying the same in the future, this page should make the solution clear: grymoire.com/Unix/Sed.html#uh-29 –  Cleber Goncalves Apr 9 '13 at 9:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.