Replace text in a file using sed on windows - windows

I am trying to replace a string in a .ism file using the SED command but it is failing for me.
The line in the file is the product version which I want to change in every build.
<row><td>ProductVersion</td><td>1.0.0</td><td/></row>
And here is the command I'm trying:
c:\rt_cygwin\bin\sed -i -r "s/ProductVersion\\"+[0-9].+[0-9].+[0-9]
/ProductVersion\"1.0.%BUILD_NUMBER%/" "D:\lm.ism"
Thanks

c:\rt_cygwin\bin\sed -i -r "s/ProductVersion</td>[0-9].[0-9].[0-9]/ProductVersion 1.0.%BUILD_NUMBER%/" "D:\lm.ism"
You have extra quotes that is not in the example line that should be removed and as #jeb pointed out the portion is missing.

Related

Changing specific word in a file with Bash

I have a file /etc/singularity/singularity.conf which has the following line:
mount dev = no
I want to automatically change no to yes. I can get this line:
grep "mount dev = no" /etc/singularity/singularity.conf
But how can I edit it to be yes in the file?
sed 's/\(mount dev = \)no/\1yes/' /etc/singularity/singularity.conf
The command above just writes the output to the console. If you want the changes to be applied to the file, you can pass the -i flag, i.e. sed -i ...
You could do this using sed matching the line pattern:
sed '/mount dev =/s/no/yes/' /etc/singularity/singularity.conf
Make sure to add the -i parameter to actually overwrite the file.

Why running sed command cutting my path first letter?

sed -i s/CUSTOMER_UNIT=".*"/CUSTOMER_UNIT="Test" core/src/main/java/com/appname/core/AppConstants.kt
I am running this sed command as a result I get this
sed: ore/src/main/java/com/appname/core/AppConstants.kt: No such file or directory
It remove the first letter of core -> ore
but if I just run command find ore/src/main/java/com/appname/core/AppConstants.kt it this file exists
I am not sure if you are trying to have the results = core or ore
but when i replicate I am able to get core. One thing I noticed is in your example you are missing the terminating / for your sed command after "Test"
sed -i s/CUSTOMER_UNIT=".*"/CUSTOMER_UNIT="Test"/ core/src/main/java/com/appname/core/AppConstants.kt
sed: can't read core/src/main/java/com/appname/core/AppConstants.kt: No such file or directory
if you are trying to cut the C from core and you can manually validate the path exists I would be sure that you have proper permissions
The command should be enclosed in quotes and be ended with "/".
sed -i 's/CUSTOMER_UNIT=".*"/CUSTOMER_UNIT="Test"/' core/src/main/java/com/appname/core/AppConstants.kt

Sed command from command line into script

I want the string index.xml to be appended when I see something ending in /feed/ and starting with http://a.b.c
Using the command line I wrote, and works, this
echo "http://a.b.c/blabla/feed/" | sed -e 's#\(http://a.b.c/.*/feed/\)#\1index.xml#g'
I don't know how to transform this code so that it works in a script using -i and a file as parameter.
I tried the following but it works only if the searched string is on a line alone, while I need to transform also strings between other text. What's the correct code?
#!/bin/bash
sed -i 's#\("http://a.b.c/.*/feed/"\)#"\1index.xml"#g' $1
I think
#!/bin/bash
sed -i 's#\(http://a.b.c/.*/feed/\)#\1index.xml#g' "$1"
should work. I only removed the wrong double quotes in the command and added the missing ones around the $1.
If an input like http://aXbXc/ is not supposed to trigger the replacement, then you should also escape the dots.

replace some string after certain other string with sed

In my config file I have an asset version like:
templating:
engines: ['twig']
assets_version: 20161021
When i plan to make a new release i want to replace current version (in this case 20161021) in a bash script with new version (for example with current date).
i have searched long time for examples of sed use but without success.
My Code:
sed -e 's/(::\s+assets_version:)[^=]*$/\1 assets/' app/config/config.yml
But console told me: sed: 1: "s/(::\s+assets_version: ...": \1 not defined in the RE
Can anybody help?
VERSION=20161101
sed -i "s/assets_version.*/asserts_version: ${VERSION}/" app/config/config.yml
-i to change on the same file
assets_version.* matches assets_version and any more character on the line then replace them.

bash - replacing string with sed

For some mysterious reason, some elements in my CSV data appear as s/stWgvN52??f2& ?" instead of stWgvN522tw0JtZZnyXj, which messes up the file because I have ; set as the CSV delimiter.
I attempted to replace the defective string using sed as follows:
$ sed -i 's/stWgvN52??f2& ?"/stWgvN522tw0JtZZnyXj/g' file.csv
but I get the following error:
sed: 1: "access_logs_2014-04.csv": command a expects \ followed by text
What is the reason?
When you use the -i option, you have to specify the extension of the backup file that gets made. Some versions of sed expect the extension directly appended to the -i option, so what you wrote would work. But other versions (like the version on OS X) require it to be a separate option, so you have to write:
sed -i '' 's/stWgvN52??f2& ?"/stWgvN522tw0JtZZnyXj/g' file.csv
to specify that you don't want a backup file.

Resources