Hi everyone,
I am having trouble looping through entries in a file. The file several entries that are separated by topics e.g.
<Topic r:id="Top/World/Fran�ais">
</Topic>
<Topic r:id="Top/World/Fran�ais/Actualit�">
</Topic>
<Topic r:id="Top/World/Fran�ais/Actualit�/A_la_Une">
<link r:resource="http://www.pluralworld.com/"/>
<link r:resource="http://www.webdopresse.ch/"/>
<link r:resource="http://www.largeur.com/"/>
</Topic>
<Topic r:id="Top/World/Fran�ais/Actualit�/Info-trafic">
<link r:resource="http://www.quelleroute.com/"/>
<link r:resource="http://www.transvalley.com/"/>
</Topic>
I want to be able to print out, for each entry, the name of the topic and then any links that appear within. In this case, I would like to print out:
Topic "Top/World/Fran�ais"
Topic "Top/World/Fran�ais/Actualit�"
Topic "Top/World/Fran�ais/Actualit�/A_la_Une"
"http://www.pluralworld.com/"
"http://www.webdopresse.ch/"
"http://www.largeur.com/"
Topic "Top/World/Fran�ais/Actualit�/Info-trafic"
"http://www.quelleroute.com/"
"http://www.transvalley.com/"
I can't seem to separate the topics and then get in at their details. This is my attempt to far:
#!/bin/sh
inputFile=$1
PARAGRAPHS=`sed -n '/<Topic r:id=\"Top\/World\/Fran�ais/,/<\/Topic>/p' $inputFile`
n=0
for p in $PARAGRAPHS
do
URLS=`sed -n '/<link r:resource=/,/>/p' $p`
for url in $URLS
do
echo "$url"
done
done
Can anyone help me please, I'm new to this?