sed script to change the value
Hi,
I need your help as I am weak in sed and regular expressions. I am trying to alter the value of one configuration file from XML to LDAP.(Oracle Application Server) sed -e 's/XML/LDAP/g' $ORACLE_HOME/j2ee/${OC4J_INSTANCE}/application-deployments/SPLWebApp/orion-application.xml Oracle Home and OC4J Instance Values would be passed to script. The actual node in file(orion-application.xml) look's like this, <jazn provider="XML" /> so this is to be change to <jazn provider="LDAP" /> I have question to you what I have done is there any better way? any more defensive technique I can use with this? Thank you for your assistance. |
Well as there is only one on the line the 'g' at the end is not required. The only thing to make it stricter would be to include the entire entry.
|
Rightly said that way we can make it more defensive however it gives me error as now i do like this.
sed -e 's/<jazn provider="XML" />/<jazn provider="LDAP" />//' $ORACLE_HOME/j2ee/${OC4J_INSTANCE}/application-deployments/SPLWebApp/o rion-application.xml sed: -e expression #1, char 27: unknown option to `s' Can you please tell me in sed when you put \? I am confused when you put \. To my little knowledge you put \ just before space " " -- quotes removed, =,!,#,$,%,^,&,*,(,) that is for all special characters right? Please guide. Thanks. |
It's complaining about the '/'. Change it to:
Code:
sed -e 's/<jazn provider="XML" \/>/<jazn provider="LDAP" \/>//' $ORACLE_HOME/j2ee/${OC4J_INSTANCE}/application-deployments/SPLWebApp/o |
Or the nice thing about sed when do a substitution you can simply change the delimiter:
Code:
sed -e 's@<jazn provider="XML" />@<jazn provider="LDAP" />@' $ORACLE_HOME/j2ee/${OC4J_INSTANCE}/application-deployments/SPLWebApp/orion-application.xml |
Thank you Snark and grail
Snark If i Run the way it was given by yourself. sed -e 's/<jazn provider="XML" \/>/<jazn provider="LDAP" \/>//' $ORACLE_HOME/j2ee/${OC4J_INSTANCE}/application-deployments/SPLWebApp/orion-application.xml Then changed it to, sed -e 's/<jazn provider="XML" \/>/<jazn provider="LDAP" \/>/' $ORACLE_HOME/j2ee/${OC4J_INSTANCE}/application-deployments/SPLWebApp/orion-application.xml why it worked later and not the former? I feel the former shoudl also work? instead of g we are having nothing "/" so why shell complains? grail the one way gave so ran without any issues. Thanks Guys. |
Quote:
Code:
sed -e 's/<jazn provider="XML" \/>/<jazn provider="LDAP" \/>//' $ORACLE_HOME/j2ee/${OC4J_INSTANCE}/application-deployments/SPLWebApp/orion-application.xml |
Thanks grail! :)
Your logic also helped me in another automation! :):):) Have a look at this <session-timeout>any damn value donesn't mattter</session-timeout> to be changes to <session-timeout>-1s</session-timeout> I did like this, sed -e 's@<session-timeout>*.*</session-timeout>@<session-timeout>-1s</session-timeout>@' file.xml ant it works well. My question, 1) Is there any other way to do 2) Most important once script is run is the file going to be saved with new values? without altering the other contents of file ? how can we achieve that? |
Got that but new challenge but that would be in new thread!
Thank you for your assistance. |
For GNU See you can use the -I option to edit the file in place. You can also redirect the output to a file. Don't redirect the output. To the same file as the input or you will replace the input file with an empty file before see runs.
|
Thanks jschiwal I commited that mistake :( before your post :( small little helps in a big learning curve! :)
|
Quote:
|
All times are GMT -5. The time now is 09:35 PM. |