Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Though i do understand how to use sed command and it's very easy but i am stuck in a situation where i need to change one value but it's changing all value.
Below i have component name with their version. Suppose if i want to change the component2 version says v2, then component5, component7 get also affected.
gauravrishi@administrator-ThinkPad-L470:/tmp$ cat 1.txt
component1: "v44"
component2: "v1"
component3: "v17"
component4: "v664"
component5: "v152"
component6: "v220"
component7: "v100"
component8: "v434"
You need to understand the effect of single versus double quotes - and the effect on the shell.
I prefer to use double quotes to allow natural variable substitution, and escape embedded double quotes (preferably avoid them altogether) - like this
Code:
sed "s/\"${current_version}\"/\"${new_version}\"/" buildVersion.yaml
Normally the sed code should be in 'ticks'; your code correctly has the shell variable outside so the shell can substitute them.
But they must not contain special characters. If you want to allow special characters the variables must be in "quotes" for the shell to only substitute but not further expand them:
Code:
sed 's/"'"${current_version}"'"/"'"${new_version}"'"/'
For demonstration I put these quotes in red - in reality the chain "'" looks a bit confusing.
Therefore, in this case, putting the sed code in "quotes" is a good alternative.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.