I want to replace '-Djava.library.path=""' with '-Djava.library.path="path"' in file named "file" using sed
sed -i 's/-Djava.library.path=""/-Djava.library.path="path"/g' -f file
returns
sed: 2: file: unescaped newline inside substitute pattern
What's wrong? Can someone help?
Changed to
sed -i 's/Djava.library.path=""/Djava.library.path="path"/' file
Now it works.
Related
I know how to replace sting via sed:
sed -i "s|.*#app-${BRANCH}-log.*| Path ${LOG_PATH} #app-${BRANCH}-log|" /etc/td-agent-bit/td-agent-bit.conf
and this is work for file like
[INPUT]
Name tail
Path /var/lib/docker/containers/f774c1a3689dfffb2528833ac2ded629c3b1873fd3af96fe0cf1f041f22f88d8/f774c1a3689dfffb2528833ac2ded629c3b1873fd3af96fe0cf1f041f22f88d8-json.log #app-develop-log
Tag app.develop
Interval_Sec 1
but how to replace next line? for example:
#This line just for triggering sed
And this one must be replaced
Any idea? Sorry for my horrible English.
With GNU sed:
sed '/^#This line just for triggering sed$/{n;s/.*/foo/}' file
Output:
#This line just for triggering sed
foo
See: man sed
How to search a pattern and remove the line using sed which contains special characters like "ranasnfs2:/SA_kits/prod"
I tried using a variable to hold the complete string and then recall the variable in sed command but it is not working.
echo $a
ranasnfs2:/SA_kits/prod
sed -i '/"$a"/d' test.txt
cat test.txt | grep -i SA
/SA_kits -rw,suid,soft,retry=4 ranasnfs2:/SA_kits/prod
You need to escape the slash character.
Use this for deleting lines which contain a /:
sed '/\//d' file
I have the following line in a file:
$app-assets:"/assets/";
I am trying to use sed in the terminal to overwrite that line to read as follows:
$app-assets:"http://www.example.com/assets/";
I have tried the following but it does not work:
sed -i \'\' -e \'s/app-assets:"/assets/"/app-assets:"http://www.example.com/assets/"/g\' myfile.txt
I am fine using Perl if easier.
Use the following sed approach:
sed -i 's~\(\$app-assets:"\)\(/assets/\)"~\1http://www.example.com\2"~' myfile.txt
~ here is treated as sed subcommand separator
sed 's/app-assets:\"\/assets\/\";/app-assets:\"http:\/\/www\.example\.com\/assets\/\";/g' filename
remove everything in a file from to in /etc/tomcat7/tomcat-users.xml
sudo sed '/<tomcat-users>/,/</tomcat-users>/d' /etc/tomcat7/tomcat-users.xml
error:
sed: can't find label for jump to omcat-users>/d
What is wrong with the syntax?
Try
sed '/<tomcat-users>/,/<\/tomcat-users>/d' /etc/tomcat7/tomcat-users.xml
---^
The / needs to be escaped
To remove that section from the input use the -i flag
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if extension supplied)
i.e.
sed -i '/<tomcat-users>/,/<\/tomcat-users>/d' /etc/tomcat7/tomcat-users.xml
Why not just change the separator in sed
sed ':<tomcat-users>:,:</tomcat-users>:d' /etc/tomcat7/tomcat-users.xml
Then you do not need to escape the /
I want to replace the
/fdasatavol/ankit
to
/fdasatavol_sata/ankit
Can anyone help me out in this?
to write to a new file (without modifying file1):
sed 's/fdasatavol/fdasatavol_sata/g' file1 > file2
or to replace in the original file:
sed -i 's/fdasatavol/fdasatavol_sata/g' file1
This will replace each occurrence of fdasatavol with fdasatavol_sata:
sed 's/fdasatavol/&_sata/g'
If your input has occurrence of fdasatavol that are not in /fdasatavol/ankit and you don't want to substitute these then use:
sed 's#/fdasatavol/ankit#/fdastatavol_sata/ankit#g'
Note: you can use any character as sed's delimilter to aviod the confusion with the parrtern contiaing /. sed prints to stdout by default, if you are happy with the changes produced by sed you can use the -i option to store back to the file.
sed -i 's/fdasatavol/&_stat/g' file