read mp3 filename and create one XML for each file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read mp3 filename and create one XML for each file
# 1  
Old 03-20-2009
Question read mp3 filename and create one XML for each file

Hi:

I have a collection of mp3s and I need to create 1 xml file per mp3.

I have:

recording1.mp3
recording2.mp3
etc

and I want to generate this kind of files.

recording1.xml
recording2.xml

and inside each xml file I need to add a url prefix and then the filename at the end.

So if my url is www.servername.com/mp3s

i need to have inside the xml something like

<file>www.servername.com/mp3s/recording1.mp3</file>

for the second file
<file>www.servername.com/mp3s/recording2.mp3</file>

Like that.

I have run into some issues so I would like to know from you guys.

Thanks in advance.

ps. if it works in subfolders too then you are my shell god.
# 2  
Old 03-21-2009
You may try something like this (assuming unique filenames with no embedded newlines, I also assume that you want to store all xml files in the current directory):

Code:
_url="http://www.servername.com/mp3s" export _url

find . -name '*.mp3' |
  while IFS= read -r; do
    _f="${REPLY#*/}" _p="${_f##*/}"
    printf '<file>%s/%s</file>\n' "$_url" "$_f" > "${_p%.*}.xml"
done

# 3  
Old 03-21-2009
Thanks!

just one more thing.

How should I change it so that the xml is generated next to the mp3?

so if i have

folder1/audio1.mp3
folder1/2001/recording.mp3

i get

folder1/audio1.xml
folder1/2001/recording.xml

I dont want to have all xml files on the same dir since the mp3s will be moved and I will leave the xml files as fake mp3s that link to the mp3s on the other server.
# 4  
Old 03-21-2009
This should work:

Code:
_url="http://www.servername.com/mp3s" export _url

find . -name '*.mp3' |
  while IFS= read -r; do
    _f="${REPLY#*/}"
    printf '<file>%s/%s</file>\n' "$_url" "$_f" > "${_f%.*}.xml"
done

# 5  
Old 03-21-2009
perfect. a million thanks.

Last edited by jason7; 03-25-2009 at 07:55 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to read a csv and create xml - Perl

I have a csv file like below. john,r2,testdomain1,john.r2@hex.com,DOMAINADMIN,testdomain1.dom maxwell,b2, testdomain1,maxwell.b2@hex.com,DOMAINADMIN,testdomain1.dom I would need the perl script to read the above csv and create an xml like below. <Users> ... (1 Reply)
Discussion started by: Tuxidow
1 Replies

2. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

3. Shell Programming and Scripting

Create one xml file from one list of names

Actually I have one list of channels names like: Rai 1 Rai 1 +1HD Rai 1 +2HD Rai 2 Rai 2 +1HD Rai 2 +2HD . . . .From this list of names I need create one new xml file with this structure <channel id="Rai 1"> <display-name lang="it">Rai 1</display-name> <icon... (3 Replies)
Discussion started by: Tapiocapioca
3 Replies

4. UNIX for Dummies Questions & Answers

Create file with last month in filename

Hi, I have a bash script which outputs a file with current year and month in the filename. Last line is: cat result_* > output.$(date +%y%m) So for Feb 2013 this gives me output.1302 Now I am requested to run the script every first day of the month, but with the previous month in... (4 Replies)
Discussion started by: viscacha
4 Replies

5. Shell Programming and Scripting

Create xml file using a content from another xml file

I need to create a xml file(master.xml) with contents from another xml files(children). I have below list of xml files in a temporary location (C:/temp/xmls) 1. child1.xml 2. child2.xml Below is the content of the child1.xml & child2.xml files, child1.xml <root> <emp> ... (3 Replies)
Discussion started by: vel4ever
3 Replies

6. Shell Programming and Scripting

Extract date from filename and create a new file

Hi, i have a filename CRED20102009.txt in a server 20102009 is the date of the file ddmmaaaa format the complete route is /dprod/informatica/Fuentes/CRED20102009.csv i want to extract the date to create a new file named Parameters.txt I need to create Parameters.txt with this... (6 Replies)
Discussion started by: angel1001
6 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

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies

9. Shell Programming and Scripting

Read xml file

Iam new to shell script. How to read xmlfile using shellscript(without awk),and Store record by record in file . My xml file: <root> <header> <HeaderData1>header1</HeaderData1> <HeaderData2>header2</HeaderData2> </header> <detailsRecord> ... (2 Replies)
Discussion started by: ram2s2001
2 Replies
Login or Register to Ask a Question