The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating an array to hold posix thread ids: Only dynamic array works kmehta High Level Programming 4 09-21-2008 09:24 PM
KSH script not looping through array kelldan Shell Programming and Scripting 2 07-18-2008 12:30 PM
creating a dynamic array trichyselva Shell Programming and Scripting 1 07-10-2008 10:13 AM
creating a dynamic array in ksh gundu Shell Programming and Scripting 3 03-09-2005 03:26 PM
Perl question - looping through an array of hashrefs kregh99 Shell Programming and Scripting 2 03-19-2004 10:48 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 4 Weeks Ago
sexyTrojan sexyTrojan is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 14
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; 4 Weeks Ago at 10:45 AM.. Reason: added code tags
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0