Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed pacman.conf remove # for multilib & include

I'm actually facing a wall with my custom installation script.

At a point of the script, I need to enable the 64 bits repository for 64 bits machines and (for instance) I need to get from that format :

#multilib-testing[...]
#include[...]

#multilib[...]
#include[...]

To that format

#multilib-testing[...]
#include[...]

multilib[...]
include[...]

But as you can see, there are include everywhere and I can't use sed because it will recursively delete all the "include" of that specific file and it's not what I want...

I can't seem to find a solution with sed. I tried something I saw on another thread with

cat /etc/pacman.conf | grep -A 1 "multilib"

But I didn't get it well and I'm out of options...

Ideally, I would like to get a sed solution (but feel free to tell me what others options I could get as long as you explain !).

The pattern (and the beginning) shoud be something like that :

sed -i '/multilib/ s/#//' /etc/pacman.conf

And should be effective for the pattern and the line after (which is the include).

Also, I will be pleased if you could actually teach me why you do that or that as I'm learning and I can't remember something if I can't figure why I did like that. (also excuse my mid-game english).

like image 651
Amin NAIRI Avatar asked Dec 29 '15 16:12

Amin NAIRI


1 Answers

We can use this to match a range by patterns. We can then match the # at the beginning of each line and remove it.

sed -i "/\[multilib\]/,/Include/"'s/^#//' /etc/pacman.conf
like image 111
Evan Graham Avatar answered Nov 15 '22 04:11

Evan Graham