Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


how to replace 5th line using bash script !
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

how to replace 5th line using bash script !

i need to replace 5th line of remi.repo file using bash script. i try to do it using sed command and i failed to do it using sed. please help me to correct my errors. this is my remi.repo file's first 7 lines located in /etc/yum.repos.d/ ...


[remi]
name=Les RPM de remi pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

now i need to change 5th line enabled=0 to enabled=1 .

this sed command working and echo result with enabled=1 but it not saved in remi.repo file. please help me to do this. thank you so much.

sed -n -e "5s/enabled=0/enabled=1/" remi.repo

Comments

  • sed -i

  • AnthonySmithAnthonySmith Member, Patron Provider

    sed -i 's/enabled=0/enabled=1/g' remi.repo

    ^^ that will work assuming you dont have "enabled=0" anywhere else in the file.

  • @rds100 : sed -i is working thank you so much ... :D
    @AnthonySmith : there is another 4 or 5 enable=0 in my configuration file ... anyway thank you so much for the help sed -i is working ... :D

  • sed -i 's/enabled=0/enabled=1/g' remi.repo --> /g = replace every occurrence

    sed -i 's/enabled=0/enabled=1/' remi.repo --> no /g = replace the first occurrence

Sign In or Register to comment.