Sponsored Content
Full Discussion: Looping through entries
Top Forums Shell Programming and Scripting Looping through entries Post 302211407 by BlueberryPickle on Thursday 3rd of July 2008 09:02:30 AM
Old 07-03-2008
Looping through entries

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?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help with looping

Hi, Actually I have a file which consists data . for eg names. Then I want my sql query to read this file and produce the output. Currently I am using this FOR EG : FILENAME is NAMES for i in `cat NAMES` { sqlplus -s $CONNECTID << EOF spool rooh set heading off select... (1 Reply)
Discussion started by: rooh
1 Replies

2. Shell Programming and Scripting

looping

Hi I have around 100 users in sun server and have default home directory in /usr/home/<username> I want to clean their home directory time to time to make free space on root, as users generate many output files during usage of application. My idea is, generate a file with following command... (4 Replies)
Discussion started by: ishir
4 Replies

3. Shell Programming and Scripting

Looping and using Sed

Hi guys I having som problem trying to use sed to get a file and insert inside another one. I'll try to explain better. I have a base.txt and using sed(having a array variables) I'm chaging some strings inside this file and saving as base1.txt. until here okay. Then, I have to get this... (4 Replies)
Discussion started by: digobh
4 Replies

4. Shell Programming and Scripting

for looping

I run into a issue when I try to do sorting of the following with ascending order, one round of for looping seems not working, anyone knows how to use shell or perl? $array = (5,0,3,2,7,9,8) (2 Replies)
Discussion started by: ccp
2 Replies

5. Shell Programming and Scripting

help on looping using if/for or while

Hello, where can I get usefull information on the use of looping with for , if and while with extensive examples. Also use of variables in scripts (1 Reply)
Discussion started by: sam4now
1 Replies

6. Shell Programming and Scripting

help with looping

vesselNames values: xxx yyy zzz vesselPlanned values: xxx zzz zzz zzz OIFS="" OIFS=$IFS IFS="\n" (2 Replies)
Discussion started by: finalight
2 Replies

7. Shell Programming and Scripting

Looping

Hi, Now I have written a script which sorts the records in the file and splits them according to some condition. Now, I need to modify the script so that it reads all the files one after the other and does the sorting & splitting. Pls help me in reading all the files in a directory and... (8 Replies)
Discussion started by: Sunitha_edi82
8 Replies

8. Shell Programming and Scripting

Looping

Hi evryone i need a help . i have a file xcv.the content is : accelerate i want a script which will run 1000 times in loop and changing the value to accelerate to acceler in 1st loop and in 2nd loop it will be again accelerate and so on . (6 Replies)
Discussion started by: Aditya.Gurgaon
6 Replies

9. Shell Programming and Scripting

Looping

Hey guys, so I am trying to do a loop script that will go through each folder (no gui so just each domain has a folder) and grab out the databases being used on that domain. I know I would use mysql -e "show databases where not 'information_schema';" once in each directory to pull the actual... (3 Replies)
Discussion started by: dough
3 Replies

10. UNIX for Beginners Questions & Answers

Need info on looping

My script will do: while true do if ]; then ### here im mailing content of file.txt fi if ]; then exit 0 fi sleep 30m done If i add exit 1 after ### mail, script is getting stopped. Can you please suggest, how to implement above requirement. Mine is Linux machine. (11 Replies)
Discussion started by: JSKOBS
11 Replies
COLORS(3)						   libbash colors Library Manual						 COLORS(3)

NAME
colors -- libbash library for setting tty colors. SYNOPSIS
colorSet <color> colorReset colorPrint [<indent>] <color> <text> colorPrintN [<indent>] <color> <text> DESCRIPTION
General colors is a collection of functions that make it very easy to put colored text on tty. The function list: colorSet Sets the color of the prints to the tty to COLOR colorReset Resets current tty color back to normal colorPrint Prints TEXT in the color COLOR indented by INDENT (without adding a newline) colorPrintN The same as colorPrint, but trailing newline is added Detailed interface description follows. Available colors: Green Red Yellow White The color parameter is non-case-sensitive (i.e. RED, red, ReD, and all the other forms are valid and are the same as Red). FUNCTIONS DESCRIPTIONS
colorSet <color> Sets the current printing color to color. colorReset Resets current tty color back to normal. colorPrint [<indent>] <color> Prints text using the color color indented by indent (without adding a newline). Parameters: <indent> The column to move to before start printing. This parameter is optional. If ommitted - start output from current cursor position. <color> The color to use. <color> The text to print. colorPrintN [<indent>] <color> The same as colorPrint, except a trailing newline is added. EXAMPLES
Printing a green 'Hello World' with a newline: Using colorSet: $ colorSet green $ echo 'Hello World' $ colorReset Using colorPrint: $ colorPrint 'Hello World'; echo Using colorPrintN: $ colorPrintN 'Hello World' AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), libbash(1) Linux Epoch Linux
All times are GMT -4. The time now is 11:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy