perl script to update a xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl script to update a xml file
# 1  
Old 04-12-2011
perl script to update a xml file

Hi experts,

I have a set of xml files in folder which has the below field.
<mm:sessionID>157.235.206.12900397BE4:A</mm:sessionID>,
I need to update this field regularly with new session id, which I have it from a login file.

Can anyone tell me how to add a new value in <mm:sessionID> field in xml files
under the folder("/usr/home/automation/Sanity/xml/) using perl script?

Here is what I have

Code:
opendir(DIR, "/usr/home/automation/Sanity/xml/");
my @ssl = grep /\.xml$/, readdir(DIR); close(DIR);
foreach $ssl (@ssl) {
    
    open(SSL, "$ssl");
    my @in = <SSL>;
    close(SSL);
      foreach (@in) {
        s/sessionID/$SID/;
       }
}

Thanks

varma

Last edited by radoulov; 04-12-2011 at 08:12 AM.. Reason: Code tags, please!
# 2  
Old 04-12-2011
If you want to replace mm:sessionID then use
Code:
s/(<\/|<)mm:sessionID>/$SID/g;

instead of
Code:
s/sessionID/$SID/;

# 3  
Old 04-12-2011
Hi Pravin,
Thanks for the help,

I want to replace the value mentioned between <mm:sessionID> <\mm:sessionID>?
but one you send this will change the "<mm:sessionID>" only right?

varma
# 4  
Old 04-12-2011
Yes, Then try this,
Code:
s/<mm:sessionID>(.+?)<\/mm:sessionID>/<mm:sessionID>$new_value<\/mm:sessionID>/;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX/PERL script to convert XML file to pipe delimited format

Hello, I need to get few values from a XML file and output needs to be written in another file with pipe delimited format. The Header & Footer of the Pipe Delimited file will be constant. The below is my sample XML file. I need to pull the values in between the XML tags <Operator_info to... (15 Replies)
Discussion started by: karthi1305561
15 Replies

2. Windows & DOS: Issues & Discussions

Update sh file using VBA before perl script is run

I have a VBA that creates a new directory folder and creates a new text file in that directory. I am trying to run a perl script from the VBA and have created a batch file that gets called from the VBA. That bat file uses a shell file to run a script. When the batch file is called I get the error... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Splitting xml file into several xml files using perl

Hi Everyone, I'm new here and I was checking this old post: /shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html (cannot paste link because of lack of points) I need to do something like this but understand very little of perl. I also check... (4 Replies)
Discussion started by: mcosta
4 Replies

4. Shell Programming and Scripting

Script need to do update xml file

<avp name="CC-Request-Type" value="1"> </avp> <avp name="CC-Request-Number" value="0"> </avp> <avp name="Subscription-Id"> <avp name="Subscription-Id-Type" value="0"></avp> <avp name="Subscription-Id-Data" value="4081234567"></avp> </avp> <avp... (5 Replies)
Discussion started by: gstar
5 Replies

5. Shell Programming and Scripting

Get multiple values from an xml file using one of the following commands or together awk/perl/script

Hello, I have a requirement to extract the value from multiple xml node and print out the values to new file to compare. Would be done using either awk/perl or some unix script. For example sample input file: ..... ..... <factories xmi:type="resources.jdbc:DataSource"... (2 Replies)
Discussion started by: slbmind
2 Replies

6. Programming

help need in the perl script that create one xml file form multiple files.

Hi every one, Please excuse me if any grammatical mistakes is there. I have multiple xml files in one directory, I need to create multiple XML files into one XML file.example files like this</p> file1:bvr.xml ... (0 Replies)
Discussion started by: veerubiji
0 Replies

7. Shell Programming and Scripting

How to create a xml file using Perl Script

Hi All, I have some data which needs to be saved in the xml file format.Can you guys please let me know how to do this using perl script. NOTE: the template of the xml file shall be depending on validation of the data done for some requirements. Basically to summarise, the fields in the xml... (5 Replies)
Discussion started by: girish.raos
5 Replies

8. Shell Programming and Scripting

Perl: update lastmod in xml file

I'm trying to write a perl script that I can run as a cron job in root of my web server that will look for .shtml files get their last modified date and replace it in the sitemap_test.xml file. the problem is the substitution doesn't work and when I print to MYFILE it adds the lastmod to the end of... (3 Replies)
Discussion started by: skilodge
3 Replies

9. Shell Programming and Scripting

Perl script to extract 'ID' From XML File

File1.xml <?xml version.........> - <abcd:abcd_list version="1" www.john_uncle's_server.com" xmlns: - <device id="100"> <firmware>12.4(3d)</firmware> <location id="500">Sitting Room</location> </device> - <device id="101"> <firmware>12.4(3d)</firmware> <location id="501">Class... (1 Reply)
Discussion started by: sureshcisco
1 Replies

10. Shell Programming and Scripting

How to parse a XML file using PERL and XML::DOm

I need to know the way. I have got parsing down some nodes. But I was unable to get the child node perfectly. If you have code please send it. It will be very useful for me. (0 Replies)
Discussion started by: girigopal
0 Replies
Login or Register to Ask a Question