text replacement help

Post Reply
Message
Author
User avatar
dolphin_oracle
Developer
Posts: 20024
Joined: Sun Dec 16, 2007 1:17 pm

text replacement help

#1 Post by dolphin_oracle »

in a bash script I need to replace 2 words in a string with new words. I know one of the words, and the other follows. For instance

Code: Select all

xserver_arguments -dpi 120 -nolisten tcp
needs replaced so that the 120 is something else. the -dpi is the parameter to change.

Order is not ensured, nor is the presence at all.. however, I can test for the presence of the parameter ahead of time, so I can append or replace as needed.

any help is appreciated. this will fix a bug in an antiX settings app.

TIA

d.o.
http://www.youtube.com/runwiththedolphin
lenovo ThinkPad X1 Extreme Gen 4 - MX-23
FYI: mx "test" repo is not the same thing as debian testing repo.

User avatar
Adrian
Developer
Posts: 8269
Joined: Wed Jul 12, 2006 1:42 am

Re: text replacement help

#2 Post by Adrian »

Not a sed master by any measure, would this work?

Code: Select all

sed -i  's/-dpi [^ ]*/-dpi 200/' filename
That should replace "-dpi xxx" with "-dpi 200"

Try different version of the string here https://regexr.com/ (use only the first part of the sed expression to see what it matches)

User avatar
dolphin_oracle
Developer
Posts: 20024
Joined: Sun Dec 16, 2007 1:17 pm

Re: text replacement help

#3 Post by dolphin_oracle »

ah, looks promising, thanks!

*edit* yep, that does the trick
http://www.youtube.com/runwiththedolphin
lenovo ThinkPad X1 Extreme Gen 4 - MX-23
FYI: mx "test" repo is not the same thing as debian testing repo.

Post Reply

Return to “General”