Multidimentional arrays in KSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multidimentional arrays in KSH
# 1  
Old 12-14-2011
Multidimentional arrays in KSH

Hi,

I am using KSH shell and need to define a multi dimensional array in which i need to store and retrive data. Please provide your valuable in puts.
Eg: asbjkasd 1234
asdhnas 1254
i need to store the above values and use them as input to another command.
Note each line is a pair.
Thanks for your help in advance.
# 2  
Old 12-14-2011
Why do you need multi dimensional array for that?... besides, I am not sure if KSH has it... Bash v4 got multi-dim array support...
What is your goal?... Give us some more information...

--ahamed
# 3  
Old 12-14-2011
Hi,

Here is the scenario, i run a command and need to parse it to the next command to perform a action, but the trick part is the first command can provide 1 or more lines of output but with the 2 words separated by space in each line. The 2 words are to be passed together as and argument to the next command.
Hence my approach was to store them in an array and pass them one by one to the next command.
Thanks in advance.
# 4  
Old 12-14-2011
Could you post an output example and what values do you want in variables. With that, you can send to another script.
# 5  
Old 12-14-2011
A single dim array could store the arg list

eg:
Code:
#!/bin/ksh
while read arg_list
do
    line[${#line[@]}]="$arg_list"
done <<EOF
asbjkasd 1234
asdhnas 1254
-l acid 1404
-q steel 92
EOF
 
i=0
while [ $i -lt ${#line[@]} ]
do
   echo "line[$i]: ${line[i]}"
   let i=i+1
done

output:
Code:
line[0]: asbjkasd 1234
line[1]: asdhnas 1254
line[2]: -l acid 1404
line[3]: -q steel 92

# 6  
Old 12-14-2011
Hi,

The command I run is "
Code:
set -A ctm_Condarray `ctmpsm -LISTFULLDETAILS $1 |grep 'Out Condition' |awk -F '[|:]' '{print $2,$4 }'` "

Output is
Code:
 C_AI_BARIMP001_SSIS_DELFILE_OK   1215
 C_AI_BARIMP001_ARCHIVE_SSIS_OK   1215
 C_AI_BARIMP001_EGLCTL209_HC_RUN   1215

Now each of the line is sort of pair and need to be passed to another command in the script as argument like
Code:
ctmcontb -ADD C_AI_BARIMP001_EGLCTL209_HC_RUN   1215

Thanks

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 12-15-2011 at 03:20 AM.. Reason: Please use code tags for code and data samples, thank you
# 7  
Old 12-14-2011
How about
Code:
ctmpsm -LISTFULLDETAILS $1 | awk -F '[|:]' '/Out Condition/ {print $2,$4 }' | while read arg1 arg2 rest
do
    ctmcontb -ADD $arg1 $arg2
done


Last edited by Chubler_XL; 12-15-2011 at 12:12 AM.. Reason: Update to remove grep and match "Out Condition" in awk
This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh arrays

Hi, I have a ksh script in which I need to fill an array with a list of filenames. It currently works like this: set -A array \ val1 \ val2 \ val3However, I was wondering why it's not possible to do something like this to make it easier to parse values to the array: set -A array... (3 Replies)
Discussion started by: Subbeh
3 Replies

2. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

3. Shell Programming and Scripting

PERL : multidimentional array

Platform window xp, perl 8.5 ------------------------------- Input file has following data: ABC|asd|asadd|aadd|addff|.............|zxv| ABC|asd|asadd|aadd|addff|.............|zxv| ABC|asd|asadd|aadd|addff|.............|zxv| Here '.........' indicates x number of elements, in between.... (7 Replies)
Discussion started by: shristi
7 Replies

4. Shell Programming and Scripting

KSH: Reading a file line by line into multiple arrays

Hi - I have a file that contains data in this format:- #comment value1 value2 value3 #comment value4 value5 value6 value7 #comment value8 value9 I need to read value1, value2 and value3 into one array, value4 value5 value6 and value7 into another array and value8 and value9 into a 3rd... (2 Replies)
Discussion started by: sniper57
2 Replies

5. UNIX for Dummies Questions & Answers

Arrays in nawk and ksh

I'm not confident at all on how arrays work. I want to know how to set arrays in ksh and in nawk (is there a difference??) if someone can show me some examples of both that will be great. Tried to look up on the net but was confusing me more. Any help would be appreciated. (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

6. Shell Programming and Scripting

Export Arrays in ksh

Hello everybody! Why I can export arrays in ksh? I trie this for exemplo: In parent script array=a array=b array=c export array When I see the variable array in child script there are only first index. For exemplo in child script +echo ${array} a (3 Replies)
Discussion started by: ricardo.ludwig
3 Replies

7. Shell Programming and Scripting

List of arrays in ksh?

Hi all, In a loop, i am creating an array of integer and adding it to another array that hold arrays // psuedo code pttrnArray=$type$data // This is array of integers. pttrnArrays=${pttrnArray} // This is supposed to be array of arrays. But when i print pttrnArrays, i get only the... (1 Reply)
Discussion started by: jakSun8
1 Replies

8. Shell Programming and Scripting

Automatic Arrays in ksh

Given a line of text in ksh: string1 string2 string3 .....stringn is there a way of automatically assigning each string to an array element? Or just different variables would do. Thanks, Jon (1 Reply)
Discussion started by: Jonny2Vests
1 Replies

9. Shell Programming and Scripting

ksh script - arrays

hello all.. I have been browsing / searching through the forum and have yet not been able to find what I was looking for. I am fairly new to ksh and my task is to create a function that reads in an input file: ***************** 2 3 1 abc def ghi /dev/sid/ *****************... (13 Replies)
Discussion started by: sidamin810
13 Replies

10. Shell Programming and Scripting

KSH and arrays

hello all, I browsed the forum (briefly) and I am having issues with a script I writing. I need to check a directory and see if there are files there, if so process all of them. The issues I am having is that when I create the array of files names using set -A filenames "$(ls -1... (1 Reply)
Discussion started by: whited05
1 Replies
Login or Register to Ask a Question