I have a file containing a list of information looks something like this:
#FILENAME "Some name - some title.xml"
<song>some song</song>
<year>1994.</year>
<album>Some album</album>
<artist>some artist</artist>
#FILENAME "another filename - some have ' in title title.xml"
<song>another song</song>
<year>1996.</year>
<album>another album</album>
<artist>another artist</artist>
#FILENAME "yet another filename - something.xml"
...
..
.
with more than 25 000 lines I need to create separate files (5000 files.xml) so first line is FILENAME second to fifth lines are informations that need to be fields in xml file that looks like this:
<?xml version='1.0' encoding='UTF-8'?><Metadata> <artist></artist> <song></song> <album></album> <year></year></Metadata>
Can someone help me with the script?
So far I have removed # form FILENAME from the document and done something like this:
But can't manage to create multiple files
#!/bin/bash
while read line;
if [[ $line == FILENAME* ]]; then
filename="${line:9}"
fi
if [[ $line == *artist* ]]; then
artist=$line
fi
if [[ $line == *song* ]]; then
song=$line
fi
if [[ $line == *album* ]]; then
album=$line
fi
if [[ $line == *year* ]]; then
year=$line
fi
do
echo "<?xml version='1.0' encoding='UTF-8'?><Metadata> $artist $song $album $year</Metadata>"
done < popis.txt > $filename