How to find length of multidimension array ???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find length of multidimension array ???
# 1  
Old 04-23-2013
How to find length of multidimension array ???

Does anyone know how to find length of multi dimension array
of following type

Code:
A[FILE,INDEX,COLUMN]

Code:
A[INDEX, COLUMN]

for simple array I is to do

Code:
for (i in A)n++

to find length of array but if it is multi dimension how to find the length ?
# 2  
Old 04-23-2013
What language is this?

It looks like awk, but awk doesn't have "multidimensional arrays" as such... Just a big list of indexes and elements. When you give more than one index, it actually crams them into a string like INDEX1 SUBSEP INDEX2 SUBSEP INDEX3.

So your method would still count every individual element of a multidimensional awk array. But they would have to all be filled. Any unset elements would not be counted.
# 3  
Old 04-23-2013
Thanks Corona for reply

I tried like this to remove blank fields
Worked fine

Code:
for(i=1;i<=10;i++)
        if(A[1,i,1]=="")
            print "Blank"
        else
            {
            f++
            for(m=1;m<=5;m++)
            F[f,m]=A[1,i,1] 
            }

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Array length: ls and sort

Hi there, I'm listing files and sorting them. When I try to get length of array variable in which these files are stored I get 1 as value. That's weird. files_info="$(find $input_dir -name "*_CHR$i.info" | sort )" printf ${#files_info}"\n" #print length #--loop through... (6 Replies)
Discussion started by: genome
6 Replies

2. Programming

Integer array length

Hello; When I wrote a function to print out an array, void p_array(int arr) { int i; int size = sizeof(arr) / sizeof(int); // int size = sizeof (arr) / sizeof (arr); for (i = 0; i < size; i++) printf("%d ", arr); printf("\n"); }I could only print out the... (19 Replies)
Discussion started by: yifangt
19 Replies

3. Shell Programming and Scripting

Array Length Reports as Having Length when it is Empty?

Hello All, I have this script that does stuff like "starting, stopping & restarting" a Daemon Process running on my machine... My main question is why in part of my code (which you will see below) does the Array Length (i.e. ${#PIDS} ) return "1" when I know the Array is empty..? Here is... (17 Replies)
Discussion started by: mrm5102
17 Replies

4. Shell Programming and Scripting

Longest length of string in array

I would be grateful if someone could help me. I am trying to write a .sh script in UNIX. I have the following code; User=john User=james User=ian User=martin for x in ${User} do print ${#x} done This produces the following output; 4 5 3 6 (12 Replies)
Discussion started by: mmab
12 Replies

5. Programming

How to find length of string and pass into char array in C?

Hi All I want to take a Hexadecimal number as input and i want to find lenth of the input and pass it to char s ( char s ). I have a program to convert hexadecial to binary but it is taking limited input but i want to return binary number based on input. How? (1 Reply)
Discussion started by: atharalikhan
1 Replies

6. Shell Programming and Scripting

MAWK does not support length(array)?

As Brendan O'Conner writes in this blog, mawk is near 8 times faster than gawk, so I am going to give mawk a go, but I got errors when trying to print the length of an array in mawk using length() function, is it not supported in mawk? or there's another way to get the length of an array in mawk? ... (3 Replies)
Discussion started by: kevintse
3 Replies

7. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

8. Shell Programming and Scripting

Array length in PERL

Hi experts, How to get the length of an Array in PERL. for eg., @Var having 5 elements. regards Anent (5 Replies)
Discussion started by: anent
5 Replies

9. Programming

Multidimension character array

Hi ! I'm having problem with assigning values to a multidimensional character array. i wanted to have an array with 48 fields ,each filed being of varying size and hence have declared the array as char struct_arr; I am trying to assign values to the fileds as struct_arr = token ... (1 Reply)
Discussion started by: janemary.a
1 Replies
Login or Register to Ask a Question