LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Arch
User Name
Password
Arch This Forum is for the discussion of Arch Linux.

Notices


Reply
  Search this Thread
Old 10-02-2023, 01:14 PM   #1
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Arch
Posts: 401

Rep: Reputation: 22
Question Why is my sed now not working, it did a couple of months ago


Hi

I use sed to patch my pacman.conf file to add the multilib but for the last about 2 or 3 months it won't work.
The only thing I can think of is that the ISO that came those months had something changed.

Is use this:
Code:
sed -i 'N; s/^#\[multilib\]\n#Include/\[multilib\]\nInclude/' /etc/pacman.conf
In vim I checked that the line ends right after the ']' on the [multilib] line with 'set list'

What is going on here, have they changed the way sed works 'cos what ever I do I can't get it to work.

//B52
 
Old 10-03-2023, 07:07 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,363

Rep: Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335Reputation: 2335
In every case of that sort of thing that I fixed, I traced the cause to operator (=my) error.
 
Old 10-03-2023, 07:14 AM   #3
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554

Sed is line-oriented. It deals with single lines. That has never changed, and attempts to hack around it can be brittle, as you've discovered.

What will have changed is your input /etc/pacman.conf file - it'll now have an odd number of lines before the multilib one, and thus the N hack fails (because that relies on the correct lines being paired up).


So, instead of using Sed, why not solve this with an actual patch?

First copy the file to (e.g.) /etc/pacman.conf.custom and modify as desired, then use diff -u to create the patch:
Code:
diff -u /etc/pacman.conf /etc/pacman.conf.custom > ~/mypatches/pacman.conf.patch
Then to apply it:
Code:
patch --backup /etc/pacman.conf ~/mypatches/pacman.conf.patch
That process is scalable if there are other changes you might want to make, without needing to worry about multi-line handling or escaping certain characters.

(One can also use "git diff" and "git apply", without needing a Git repository; or indeed one can version /etc using Git if desired.)


Last edited by boughtonp; 10-03-2023 at 07:17 AM.
 
Old 10-03-2023, 10:12 AM   #4
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Arch
Posts: 401

Original Poster
Rep: Reputation: 22
Quote:
Originally Posted by business_kid View Post
In every case of that sort of thing that I fixed, I traced the cause to operator (=my) error.
Seems it was, but not the first about 13 months
 
Old 10-03-2023, 10:18 AM   #5
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Arch
Posts: 401

Original Poster
Rep: Reputation: 22
Quote:
Originally Posted by boughtonp View Post
Sed is line-oriented. It deals with single lines. That has never changed, and attempts to hack around it can be brittle, as you've discovered.

What will have changed is your input /etc/pacman.conf file - it'll now have an odd number of lines before the multilib one, and thus the N hack fails (because that relies on the correct lines being paired up).


So, instead of using Sed, why not solve this with an actual patch?

First copy the file to (e.g.) /etc/pacman.conf.custom and modify as desired, then use diff -u to create the patch:
Code:
diff -u /etc/pacman.conf /etc/pacman.conf.custom > ~/mypatches/pacman.conf.patch
Then to apply it:
Code:
patch --backup /etc/pacman.conf ~/mypatches/pacman.conf.patch
That process is scalable if there are other changes you might want to make, without needing to worry about multi-line handling or escaping certain characters.

(One can also use "git diff" and "git apply", without needing a Git repository; or indeed one can version /etc using Git if desired.)

Totally correct. Wonder how I could have missed that or totally forgot when reading man page of this.
Yeah, I'll use the patch thing. I don't think this file will change that often anyways.
Thx man
 
Old 10-03-2023, 04:51 PM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
crudini is also an option.
 
Old 10-11-2023, 11:15 AM   #7
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Arch
Posts: 401

Original Poster
Rep: Reputation: 22
Quote:
Originally Posted by shruggy View Post
crudini is also an option.
How can that change the default pacman.conf?

I use crudini (with my changes) for my install script and I like it.
Simple to use for all the parameters that I have, just . it and they are usable in my script.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/etc/ntp.conf got cleared a couple of months ago. Zexuo Slackware 4 10-07-2021 04:05 AM
Installed with an SD Card in reader months ago; lost card, won't boot (VolGroup err) sandaili Fedora 2 07-02-2008 05:19 PM
Webalizer help - analysis stopped 2 months ago jantman Linux - Server 2 10-12-2007 10:46 AM
Is Current FC3 Distro Same as 6 months ago rickh Fedora 4 05-06-2005 02:47 PM
Display troubles w/ Radeon 9000 + New MonitorHere's my scenario: Several months ago, Kujila Linux - Software 7 05-10-2004 01:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Arch

All times are GMT -5. The time now is 12:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration