sed -i switch and here document not working :(:(:(
Here is what I am trying to do.
Code:
sed -i "/<web-app>/r TEXT_TO_BE_CAPTURED" ${ORACLE_HOME}/j2ee/OC4J_CCA/application-deployments/SPLWebApp/SPLApp/orion-web.xm Basically I want to grab that text in here's document and feed in to sed with i and /r somehow it is not working..... Your assistance is highly appreicated. Thank you. |
How is a here document equivalent to a file??
|
May be I am an idiot, please educate me how to do with here document.
Your help would me much appreciated. |
Hi,
the -i option only edits files. A here document is not a file, hence the -i option is useless. What you probably want is something like this: Code:
$ sed 's/hello/hi/' << EOF > outputfilename |
I don't think s switch would work here.
I want to edit the file/update the file and save. The file would be having node as follows: <webapp> </webapp> My aim is to edit/update file such that it would end up with following. <webapp> <session-config> <session-timeout>-1s</session-timeout> </session-config> </webapp> This is what I want to achieve on the side not when should we use here document? |
Quote:
|
I was merely providing an example on how to use here documents with sed. Use whatever commands you deem fit to achieve your goal.
Quote:
Quote:
<webapp> </webapp> I want the text in discussion to be inserted in between <webapp> and </webapp> I wish to implement some intelligent scripting mechanism without using any other external file(without cat). Hope I have made it clear. Thanks. |
Instead of a HERE document, insert the sed command needed into your script:
Code:
sed -i '/<web-app>/a\ Add the lines for the text you want to add, and escape the return character with a backslash. It will be as easy to edit your script as a here document inside a script would be. Another option, since you know the contents of the file, is to replace the file in it's entirety. Code:
echo > ${ORACLE_HOME}/j2ee/OC4J_CCA/application-deployments/SPLWebApp/SPLApp/orion-web.xml '<webapp>' |
A third choice would be assuming you wish to use the /r option of sed is to actually place the text in a file and call
it as you have done: Code:
$ cat session.config |
It seems I'm leading nowhere:(:( cooking slowly n steady.
@jschiwal Your first method,work's fine but in document/configuration file I can see text but with appended "\" moreover If I run script multiple times, multiple instances of configuration text is observed:( I tried your second implementation, exactly as you prescribed, however the resultant file has only Quote:
@grail I did something like this. Quote:
Quote:
Quote:
echo $? File has a node which looks like this. Quote:
It returns zero as retun code but the configuration file is unchanged!! If I cannot implement simple subitute with sed, it is disgusting. Please help me learn the evil sed, but no wonder it is super powerful!! Thanks guys your assistance is much appreciated:):) |
So, if I understand correctly then you are not trying to edit a here document but the here document is supposed to be read by sed's r command, right? Not sure why it has to be a here document but try this:
Code:
cat > session.config << EOF |
The issue with the sed and /r is there should be no slash at the end ... my bad:
Code:
sed -i '/<webapp>/r session.config' ${ORACLE_HOME}/j2ee/OC4J_CCA/application-deployments/SPLWebApp/SPLApp/orion-web.xml |
Sorry Guys after all attempts it failing again again and again.
I can see the timestamp is updated but contents of file are not changed. Piece of code exactly in script. Quote:
Quote:
Actual file, Quote:
|
Quote:
Have a look at my post run file when ran twice!! Quote:
Quote:
|
So there are a few confusing things here:
1. Start of post #13 says the code does not work and yet post #14 says it does?? 2. If you run the code twice why would it not perform the task twice?? |
All times are GMT -5. The time now is 05:27 PM. |