Home > front end >  How can I find and replace a specific value inside a variable?
How can I find and replace a specific value inside a variable?

Time:07-25

Inside my shell script file I have the following

text="-val https://www.randomurl.com -user 1aFAd381cCCb86FD300e7a3A399a6014.test -speed 2 -save -delay 14"

I need to change the variable value so the text between "-user" and "." gets replaced by x

Like this

text="-val https://www.randomurl.com -user itWorks.test -speed 2 -save -delay 14"

How can I achieve this?

CodePudding user response:

Use 'sed' to replace your regex

echo text="-val https://www.randomurl.com -user 1aFAd381cCCb86FD300e7a3A399a6014.test -speed 2 -save -delay 14" | sed 's/-user*.*\\./-user itWorks./g'

  • Related