Help in Array looping and creating multiple lines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help in Array looping and creating multiple lines
# 1  
Old 11-02-2009
Help in Array looping and creating multiple lines

hi Gurus,

I'm a newbie in scripting please check my script if this is correct. I think there's something wrong with it but I;m not sure. I'm trying to create multiple lines using awk from external xml files but i want to add additonal info in the data manually

Since i don't knwo how to create scripts to read xml files, i will need to cut the data beforehand and save it as text files

text_files contains:
Code:
<data DAY= "MONDAY" FOOD_TYPE = "FRUITS" FRUIT_TYPE= "FRUIT_{fruit}" /data>
<data DAY="TUESDAY" FOOD_TYPE= "HEALTHY" FRUIT_TYPE= "HEALTHY_{fruit}" /data>

so I need to replaced fruit with
apple, banana, orange, pear, strwaberry and the amount of yoghurt need to be incremented by 1 starting with 23

so the output files will be
Code:
I love eating 'FRUIT_apple' with 23g of youghurt 
I love eating 'FRUIT_banana' with 24g of yoghourt

and so on

Code:
 
#!/bin/bash
 
fruit = (apple, banana, orange, pear, strawberry)
i = 23
for index in 0 1 2 3 4
do 
awk -v q="'" 'BEGIN {FS = ""}; {print "I love eating" q$3q"_"${[fruit]} "with" $i "g of yoghourt"} ' data.txt
i++
done
> output.txt
 
echo "subtituion has been made succesfully...."
 
exit 0

Thanks in advance

Last edited by Yogesh Sawant; 11-03-2009 at 10:45 AM.. Reason: added code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Looping an array of 2d arrays in C

Le sigh... Hopefully this will be the last time I have to ask for help on this topic. For a while now I've been working with a 1d array that holds 2d arrays. For reference you can view here. Now I'm just trying to loop through the elements with the following: #include <stdio.h> void... (3 Replies)
Discussion started by: Azrael
3 Replies

2. UNIX for Dummies Questions & Answers

Looping through the contents of array for output name

Hi all, I am trying to loop through the string contents of an array, to add it during the saving of the output files. I am trying this code to print each column and save it to unique file name, but it doesn't work. Thanks for any help. fnam=(japan usa uk) alldata.dat contained sample data... (1 Reply)
Discussion started by: ida1215
1 Replies

3. Shell Programming and Scripting

Creating multiple xml tag lines in a file

Hi All, Can someone tell me how can we create same xml tag lines based on the number of lines present in other file and replace the Name variable vaule present in other file. basically I have this xml line <typ:RequestKey NameType="RIC" Name="A1" Service="DDA"/> and say I... (4 Replies)
Discussion started by: Optimus81
4 Replies

4. Shell Programming and Scripting

Not looping or creating files

So my script is supposed to repeat for every server in my file, but as of now it is getting stuck on my awk commands # Read file cred.txt (with one IP per line), connect to servers (one at a time), and download directory listing i=1 param=$(sed -n "{$1}p" $parm_dir/cdm_param.txt) #Get the last... (6 Replies)
Discussion started by: MJCreations
6 Replies

5. UNIX for Dummies Questions & Answers

looping through file and creating seperate files

Hi, My first post!! I have a files with header, something like this Header_Row AMC|D1|D2|D2 AAO|D3|D4|D5 AMC|D6|D7|D8 AAO|D9|D10|D11 . . . . . and millions fo records thereafter like this. I want to read the above file in a loop and write the lines having AMC into another... (1 Reply)
Discussion started by: amitbakre
1 Replies

6. Shell Programming and Scripting

Nawk, creating a variable total from multiple lines(records)

Good Morning/Afternoon All, I am having some trouble creating a variable called "total" to display the sum of the values in a specific field, $6 for example. The data I am working on is in the following form: John Doe:(555) 555-5555:1:2:3 Jane Doe:(544) 444-5556:4:5:6 Moe Doe:(654)... (2 Replies)
Discussion started by: SEinT
2 Replies

7. Shell Programming and Scripting

How to read multiple lines from Std Input into an array

Hi All, Does anyone know how to read multiple lines from standard input into an array and then iterate a loop for all the lines read. Below is an example pseudocode: I need the below filenames to be read by the script into an array or something similar: And then in the script, I... (9 Replies)
Discussion started by: bharath.gct
9 Replies

8. Programming

Creating an array to hold posix thread ids: Only dynamic array works

I am facing a strange error while creating posix threads: Given below are two snippets of code, the first one works whereas the second one gives a garbage value in the output. Snippet 1 This works: -------------- int *threadids; threadids = (int *) malloc (num_threads * sizeof(int)); ... (4 Replies)
Discussion started by: kmehta
4 Replies

9. Shell Programming and Scripting

KSH script not looping through array

Hi All, I'm trying to get a script to loop through an array. The array is basically a list of .zip files. I'd like the script to loop through and unzip the zip files contained in the zip file list. When I run the script, it unzip the first zip file correctly, and then stops Any thoughts? Here's... (2 Replies)
Discussion started by: kelldan
2 Replies

10. Shell Programming and Scripting

Perl question - looping through an array of hashrefs

I have an array of hashrefs that look like the following: my @LAYOUT = ( {SQL_1 => "select count (*) FROM prospect WHERE PROCESS_DATE = To_date('INSERT_DATE_HERE', 'mm/dd/yyyy') and tiff_filename is not null ... (2 Replies)
Discussion started by: kregh99
2 Replies
Login or Register to Ask a Question