[SOLVED] how to update a file with some configuration changes.
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.
how to update a file with some configuration changes.
Hi Guys,
I have a challenege infront of me.
There is a configuration file which is generated post deployment say orion-web.xml Post deployment I have to append the file with contents,
<session-config>
<session-timeout>-1s</session-timeout>
</session-config>
between one node <webapp>
</webapp>
so post deployment it should look like,
<web-app>
<session-config>
<session-timeout>-1s</session-timeout>
</session-config>
</web-app>
how can we achieve this? ...
any pointers I have no clue if at all i can acheiev this.
This case would have been different if I had to change the value which would have been possible with my small little knowledge of sed.
hm, how about this:
echo '<web-app>' >output.txt
more orion-web.xml >>output.txt
echo '</web-app>' >>output.txt
er, if you need to do it in several places, this won't work. in that case, I would do search&replace;
search for: <session-config>
replace with: <web-app> <session-config>
what you are doing is adding webapp then orion-web.xml file (which is a complete file with header and footer) and then </webapp>
also where are appending we appending the nodes session config and session timeout?
so yeah we need some other mechanism, first to parse file and grep for <webapp> then add those two node values ... something like this...
The r command in sed needs a filename. content in my example was a file with the to be inserted lines. There are other sed commands like a which you can use instead when you want to do it in one line:
Code:
$ sed -i "/<web-app>/a <session-config>\n<session-timeout>-1s</session-timeout>\n</session-config>" orion.web.xml
Interesting that it doesn’t throw an error about the missing file in your case.
(Please use CODE tags, it makes it more readable.)
Last edited by Reuti; 06-17-2011 at 11:23 AM.
Reason: Rephrased
Thanks for that Perl code, at this stage I have no idea about how to use your eprl script as If i try to execute just the way gave it doesnot do anything
$ sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
$ uname -a
Linux tmelbld01 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux
<session-config>
<session-timeout>-1s</session-timeout>
</session-config>
between one node <webapp>
</webapp>
so post deployment it should look like,
<web-app>
<session-config>
<session-timeout>-1s</session-timeout>
</session-config>
</web-app>
to file orion-web.xml, I'd just put it in a file eg append.txt, then it's
Well - english is not my native language, but when he describes his effort that he wants to put stuff between <web-app> and </web-app> I would describe it with to “insert” something into the file between these tags (and he used “append” by accident). “append” in computer terms is strictly at the end of a file, although the usage in common speech might be different. So, the goal is to transform somewhere in the middle of a file:
My apologies Guys the wording was incorrct I should not said "append".
Reuti your understanding of problem is correct.
chrism01 that operation would pump out text at the end of file, I want it to be in between<webapp> and </webapp>
Reuti, no the file is created on Unix box so we can rule of windows possibility any idea how to check with od command?
I beleiev od -ox filename would be good point to check?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.