![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Display Modes | Rate This Thread |
|
|