You are not logged in.

#1 2023-06-24 12:16:32

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 409
Website

Using sed to change a line with single quotes in it

I have tried and tried to understand how to do this.
My brain just can't get the understanding it needs.
Here is what I want to do.

I want to change this line :

PRESETS=('default' 'fallback')

to be

PRESETS=('default')

It seems pretty easy , however the big problem is the single quotes.

I have read and tried every sed example but they don't work for me.
I either get no quotes or double "" quotes.

I can  post all the things I have tried if you want me to.

I even tried the sed command to replace the line but I can't get that to work either.

Thanks

Offline

#2 2023-06-24 12:46:08

edacval
Member
From: .LT
Registered: 2008-10-23
Posts: 98

Re: Using sed to change a line with single quotes in it

# sed -i '/^PRESETS=.*/ s/(.*)/('\'default\'')/' /etc/mkinitcpio.d/*.preset

Offline

#3 2023-06-24 13:13:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,470
Website

Re: Using sed to change a line with single quotes in it

You don't need to use single quotes around the sed command:

sed "/^PRESETS=/s/'fallback'//"

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2023-06-24 13:13:47

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 409
Website

Re: Using sed to change a line with single quotes in it

That worked .
Thank you so much.
Is there a good resource to learn this sed commands?

I would like to dissect that command to understand how it works.

Offline

#5 2023-06-24 13:16:18

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,470
Website

Re: Using sed to change a line with single quotes in it

My favorite sed guide is also one of the greatest exemplars of the negative correlation between a website's aesthetic design and the quality of its content:

https://www.grymoire.com/Unix/Sed.html


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2023-06-24 14:16:40

edacval
Member
From: .LT
Registered: 2008-10-23
Posts: 98

Re: Using sed to change a line with single quotes in it

Trilby wrote:

My favorite sed guide is also one of the greatest exemplars of the negative correlation between a website's aesthetic design and the quality of its content:

https://www.grymoire.com/Unix/Sed.html

I second that, its a treasure trove of information for shell warriors smile. But let me give you a free tip, @MAYBL8: never ever use shell scripting for configuration management, it is error-prone and time wasting. Use dedicated tools, start with ansible , it will cover 100% of your tasks you can think of. I will never go back to shell scripting for that even though I'm good at it.

Offline

#7 2023-06-24 23:02:12

MAYBL8
Member
From: Florida USA
Registered: 2022-01-14
Posts: 409
Website

Re: Using sed to change a line with single quotes in it

I'm using it for an arch linux install script.
This is part of the script:

#Install polkit
yes | pacman -S polkit

#Decrease writes to the USB by using the noatime option in fstab
sed -i 's/relatime/noatime/' /etc/fstab

#Prevent the systemd journal from writing to the USB it will use RAM
mkdir -p /etc/systemd/journal.conf.d
echo [Journal] >> /etc/systemd/journal.conf.d/10-volatile.conf
echo Storage=volatile >> /etc/systemd/journal.conf.d/10-volatile.conf
echo SystemMaxUse=16M >> /etc/systemd/journal.conf.d/10-volatile.conf
echo RuntimeMaxUse=32M >> /etc/systemd/journal.conf.d/10-volatile.conf

#Disable the fallback image generation and remove it from PRESETS
sed -i '/^PRESETS=.*/ s/(.*)/('\'default\'')/' /etc/mkinitcpio.d/*.preset

#Remove the existing fallback image
rm /boot/initramfs-linux-fallback.img

I don't know how to put a link to my post here but it is in the Installation section called My installation script.

Thanks

Offline

Board footer

Powered by FluxBB