Go Back   The UNIX and Linux Forums > Special Forums > Windows & DOS: Issues & Discussions
google site



Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-29-2009
Registered User
 

Join Date: Dec 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
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!
Sponsored Links
  #2  
Old 12-30-2009
radoulov's Avatar
--
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 3,619
Thanks: 15
Thanked 55 Times in 54 Posts
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
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 5,591
Thanks: 2
Thanked 68 Times in 65 Posts
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
Registered User
 

Join Date: Dec 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

Quote:
Originally Posted by radoulov View Post
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 06:01 AM.. Reason: Letter
Sponsored Links
Closed Thread

Bookmarks

Tags
file, rename, string, tag, xml

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
extract strings between tags userscript Shell Programming and Scripting 10 08-06-2009 11:21 PM
renaming files govindts Shell Programming and Scripting 4 01-06-2009 08:40 AM
Need help renaming files bbbngowc UNIX for Dummies Questions & Answers 5 04-23-2008 02:08 PM
renaming files systemsb UNIX for Dummies Questions & Answers 3 05-25-2006 12:56 AM
renaming files raguramtgr UNIX for Dummies Questions & Answers 4 09-21-2004 10:57 AM



All times are GMT -4. The time now is 07:31 AM.