Renaming files with strings from xml tags


 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Renaming files with strings from xml tags
# 1  
Old 12-29-2009
Question Renaming files with strings from xml tags

Hello!

I need to rename 400+ xml files. The name of the specific file is contained in a xml tag in the file itself.

The batch file should rename all these files with strings found in xml tags.

Every xml file has the following tags:
Code:
<footnote><para>FILENAME</para></footnote>

I have to get the FILENAME from the tag and rename the file with it.

May you possibly help me on the matter?

My system is Windows XP Professional but Linux help will be much appreciated too!

Thanks in advance!
# 2  
Old 12-30-2009
If Perl is available:

Code:
perl -ne'
    close ARGV and rename $ARGV, $1 
      if m|<footnote><para>([^<]*)</para></footnote>|
    ' xmlfile1 xmlfile2 ... xmlfilen

# 3  
Old 12-30-2009
Another one with awk:
Code:
awk -F "[<>]" '
/<footnote><para>/{f=$5;exit}
END{system("mv " FILENAME " " f)}
' file

Use nawk or /usr/xpg4/bin/awk on Solaris.
# 4  
Old 12-31-2009
MySQL

Quote:
Originally Posted by radoulov
If Perl is available:

Code:
perl -ne'
    close ARGV and rename $ARGV, $1 
      if m|<footnote><para>([^<]*)</para></footnote>|
    ' xmlfile1 xmlfile2 ... xmlfilen

Thanks a lot! Works great!

Last edited by degoor; 12-31-2009 at 07:01 AM.. Reason: Letter
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. UNIX for Beginners Questions & Answers

Splitting the XML file and renaming the files

Hello Gurus, I have a requirement to split the xml file into different xml files. Can you please help me with that? Here is my Source XML file <jms-system-resource> <name>PS6SOAJMSModule</name> <target>soa_server1</target> <sub-deployment> ... (3 Replies)
Discussion started by: Siv51427882
3 Replies

3. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

4. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

5. Shell Programming and Scripting

How to add Xml tags to an existing xml using shell or awk?

Hi , I have a below xml: <ns:Body> <ns:result> <Date Month="June" Day="Monday:/> </ns:result> </ns:Body> i have a lookup abc.txtt text file with below details Month June July August Day Monday Tuesday Wednesday I need a output xml with below tags <ns:Body> <ns:result>... (2 Replies)
Discussion started by: Nevergivup
2 Replies

6. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

7. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

8. Shell Programming and Scripting

find un-closed tags in XML files

Hi All, I am trying to validate XMLs from a folder: Input Directory having multiple XML files: File1.xml <Root> <Parent> <Child Name="One"> <Foo>...</Foo> <Bar>...</Bar> <Baz>...</Baz> </Child> <Child Name="Two"> <Foo>...</Foo>... (3 Replies)
Discussion started by: unme
3 Replies

9. Shell Programming and Scripting

Renaming by manipulating strings

hello does someone want to help me for this one ? i want to rename file by inversing parts of filenames separated by the delimiter "--" sometimes filenames have three strings : aabb4ccdd eeffgg -- 5566 -- aa78bb ccd eef gghhi.ext to aa78bb ccd eef gghhi --... (17 Replies)
Discussion started by: mc2z674gj
17 Replies

10. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies
Login or Register to Ask a Question