Using dynamic arrays to extract the values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using dynamic arrays to extract the values
# 1  
Old 12-16-2011
Using dynamic arrays to extract the values

Hi all,
We have requirement to generate load timing based on subject areas HOUSEHOLD, BANKING and TRADING. These values are stored in an array SUB_ARR
Code:
SUB_ARR=("HOUSEHOLD" "BANKING" "TRADING")

Based on indicator files produced while processing data for each type, we need to get the stats (using stats -c "%y") of when file was generated. These file names are again stored in array.

Code:
HOUSEHOLD_LIST=("HH1_FILE" "HH2_FILE" "HH3_FILE" "HH4_FILE")

similalry BANKING_LIST and TRADING_LIST

my requirement is dynamically fetch the values of LIST for each SUB_ARR value as below :

Code:
for i in ${SUB_ARR[@]}
do
  SUB_LIST=$i'_LIST'   
  <next_code_lines>
done

In next code lines, now my requirement is to fetch the values for <SUB>_LIST and assign it to variables.
eg for first iteration
SUB_LIST=$i'_LIST' would be HOUSEHOLD_LIST.
now i want to extract the value of HOUSEHOLD_LIST[0] and assign it to a varaible by modifying SUB_LIST in some way.
I tried out many ways but unsuccessful.

Would someone please provide any assistance?
Any help is apprecated.

Thanks
Sam

Last edited by Scott; 12-17-2011 at 08:30 AM.. Reason: Code tags, please...
# 2  
Old 12-16-2011
Something like this?

Code:
for i in ${SUB_ARR[@]}
do
  SUB_LIST=$i'_LIST'
  for j in $(eval echo \${$SUB_LIST[@]})
  do
    echo $j
  done
done

HTH
--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 12-17-2011
THIS WAS INDEED HELPFUL
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace sql with dynamic values

Hi Guys, I am using a function to replace the values dynamically to frame sql query by reading a file. My file will have column names like file.txt col_1 col_2 expected output: select id,col_1,col_2 from ( select a.id, a.col_1, rank() over (ORDER BY cast(a.col_1 AS double)... (5 Replies)
Discussion started by: Master_Mind
5 Replies

2. Shell Programming and Scripting

How do I find the sum of values from two arrays?

Hi I have redc containing the values 3, 6, 2, 8, and 1. I have work containing the values 8, 2, 11, 7, and 9. Is there a way to find the sum of redc and work? I need to compare the sum of those two arrays to something else, so is it okay to put that into my END? TY! (4 Replies)
Discussion started by: razrnaga
4 Replies

3. Shell Programming and Scripting

dynamic values in a row

hi i have an input file in which there are diffrent values for xxxx,yyyyyy,zzzzzzz how can i arrange the dynamic values of x,y&z in a row. input file: xxxxx 1 yyyyyy 4 yyyyyy 5 zzzzzzzz 7 yyyyyy 13 zzzzzzzz 7 zzzzzzzz 6 yyyyyy 14 yyyyyy 12 zzzzzzzz 4 yyyyyy 4 yyyyyy 5 yyyyyy 6... (6 Replies)
Discussion started by: dodasajan
6 Replies

4. Shell Programming and Scripting

arrays and two values

I have requirement where I need to capture the highest values of items from a feed that runs for N hours. For example lets assume my data looks like this first feed ======== appples 10 oranges 20 pears 14 second feed ========== apples 5 oranges 30 pears 1 Last feed... (6 Replies)
Discussion started by: BeefStu
6 Replies

5. Shell Programming and Scripting

Storing values in arrays

I have the following csh script which lets the use pass the following as an argument -legend=tag1/tag2/tag3/tag4/tag5/tag6/tag7 We pass a number of tags separated by '/'. I want to save the legend tags in an array and have done as below. How can I improve on this as things are getting quite... (3 Replies)
Discussion started by: kristinu
3 Replies

6. Shell Programming and Scripting

Cleaning up Arrays with duplicate values

Hey Gang! So I have two Arrays. @linecount and @hit. Now these arrays contain numbers which I'm using as line placeholders on files. I need these two arrays to sync up and not repeat a number. Here are the contents (spam alert) @linecount 1 28 53 86 87 88 89 90 91 92 93 94 (5 Replies)
Discussion started by: adelsin
5 Replies

7. Shell Programming and Scripting

Storing values in arrays using csh

I am reading a number of files but then I want to put the ranges xmin xmax ymin ymax as arrays for each file. Any idea how I can do this??? set j = 1 echo "Welcome $i times" while ( $j <= $i ) echo "$j" set fname = $fin-bst-misf.xy echo " "$fname ... (0 Replies)
Discussion started by: kristinu
0 Replies

8. Shell Programming and Scripting

storing values in arrays using shell

Friends, I have to execute a command and store its contents into an array using shell. this is what i have tried #!/bin/bash disk_names = ($(`iostat -xtc | egrep -v "device|nfs" | awk '{print $1}'| tr '\n' ' ' `)) But its throwing an error message as ./test-script ./test-script:... (6 Replies)
Discussion started by: achak01
6 Replies

9. Shell Programming and Scripting

Extracting dynamic values

Hi, I am stuck with extracting values by combining 2 dynamically extracted values. The code goes like this #!/usr/bin/ksh ID1="abcd" i=1 #this is a dynamic value and keeps on changing b="ID" #this is static now i want the value of ID1 variable. like echo $b$i But echo... (1 Reply)
Discussion started by: chaitanyapn
1 Replies

10. UNIX for Dummies Questions & Answers

Dynamic variable values

Bit of a newbie :D with regard to unix scripting and need some advice. Hopefully someone can help with the following: I have a predefined set of variables as follows: AAA_IP_ADD=1.1.1.1 BBB_IP_ADD=2.2.2.2 I have a funnction call which retrieves a value into $SUPPLIER which would be... (3 Replies)
Discussion started by: ronnie_uk
3 Replies
Login or Register to Ask a Question