How to initialize array with a larger number?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to initialize array with a larger number?
# 1  
Old 03-19-2010
How to initialize array with a larger number?

Language: ksh
OS: SunOS

I have been getting the 'subscript out of range' error when the below array variable gets elements greater that 1024. I understand that 1024 is the default size for 'set -A' dynamic array, but is there a way to initialize it with a larger number?

set -A arr `grep 'some pattern' filename`

Is there any other alternative to initilize arrays?

Thanks,
-CB
# 2  
Old 03-19-2010

Older versions of ksh are limited to 1024 elements in an array.
# 3  
Old 03-22-2010
Hi ,

I am facing the same problem.
I know that 1024 is the default size for 'set -A' dynamic array, but is there a way to initialize it with a larger number?
# 4  
Old 03-22-2010
Get a newer version of ksh (or use bash).
This User Gave Thanks to cfajohnson For This Post:
# 5  
Old 03-22-2010
can you explain me what is the equivalent for set -A arr `grep 'some pattern' filename`
in bash script.
# 6  
Old 03-22-2010
Quote:
Originally Posted by mr_harish80
can you explain me what is the equivalent for set -A arr `grep 'some pattern' filename`
in bash script.

Code:
arr=( $(grep 'some pattern' filename) )

(The same syntax works in ksh93.)
# 7  
Old 03-23-2010
Thanks !!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue with the incorrect number of array elements

Hello , I have a file : RestartSession.txt with the below contents : Backup p203pcrw01_OS_Weekly Failed full 10/11/2015 10:00:07 PM 1444572007 10/11/2015 10:26:23 PM 1444573583 0:00 0:26 18.76 1 08 0 0 0 2 2 180668 ... (4 Replies)
Discussion started by: rahul2662
4 Replies

2. Shell Programming and Scripting

Reduce the number of lines by using Array

I have the following code to count the number of how many times the name occurred in one file. The code is working fine and the output is exactly what I want. The problem is the real code has more than 50 names in function listname which cause function name to have more than 50 case ,and function... (14 Replies)
Discussion started by: samsan
14 Replies

3. Shell Programming and Scripting

Number of arguments to array - Perl Script

I have the following proc. proc get_add {arg1 arg2 arg3 arg4 arg 5 .. ... arg N } { } i need to count the number of arguments and also i need those arguments stored in an array. please help out ---------- Post updated at 06:33 PM ---------- Previous update was at 05:30 PM ---------- ... (1 Reply)
Discussion started by: Syed Imran
1 Replies

4. UNIX for Dummies Questions & Answers

Using UNIX Commands with Larger number of Files

Hello Unix Gurus, I am new to Unix so need some help on this. I am using the following commands: 1) mv -f Inputpath/*. outputpath 2) cp Inputpath/*. outputpath 3) rm -rf somepath/* 4) Find Inputpath/*. Now I get the following error with... (18 Replies)
Discussion started by: pchegoor
18 Replies

5. Shell Programming and Scripting

Largest number in array. Help!

I need to calculate the biggest number in array size n. Example: Users enter: 1 7 4 9 The biggest number is : 9 Simple but I'm really new on this on Shell/Bash! Anything will be helpful! Thanks! #!/bin/bash printf "\tEnter a list of numbers, with spaces: " read -a ARRAY BIG=$1... (5 Replies)
Discussion started by: Sundown
5 Replies

6. Shell Programming and Scripting

Problem to initialize ksh array when first element includes hyphen

Hi I'm trying to create an array with variable including hyphen but ksh refuses the first element set -A allArgs set +A allArgs ${allArgs} -all set +A allArgs ${allArgs} -date set +A allArgs ${allArgs} test ./test.ksh: -all: bad option(s) It happens only when first element is like... (4 Replies)
Discussion started by: gdan2000
4 Replies

7. Programming

C: Initialize "const" array from the "heap"

Hello, I am working on solving an NP-Complete problem, so it is very important that operations and data with limited integer-argument ranges be computed using immutable look-up-tables contained entirely in CPU cache. Retrieval of the look-up-table data must never leave the CPU once initially... (6 Replies)
Discussion started by: HeavyJ
6 Replies

8. Shell Programming and Scripting

How to insert the number to an array

Hi I work in ksh88 and have a file which has several "set -A " statements: set -A PNUM_LSTM 2713 4124 2635 270 2529 2259 2214 set -A PNUM_LSTM $* for pn in ${PNUM_LSTM} etc... I need to add another number, lets say 555, to the first line ONLY so only the the first line will be updated... (2 Replies)
Discussion started by: aoussenko
2 Replies

9. Shell Programming and Scripting

perl + array and incrementing number

morning guys and gals, I am haveing a problem, a friend helped me out with this script but i dont know how to add incrementing number for each movie in movie.list. this is what i have so far. any assistance would be great. I have removed the GT and LT symbols so you can see what is going on... (5 Replies)
Discussion started by: Optimus_P
5 Replies

10. Shell Programming and Scripting

eval, array, number of elements - couldn't get it

I try to get a number of elements in an array, using dynamic array name. I need the array name to be dynamic. The array name is constructed as 'inf_ln_$nmb', where $nmb is a file line number So, say I have the arr 'inf_ln_4': > for (( el=0; el<${#inf_ln_4}; el++ )); do > echo "$el:... (1 Reply)
Discussion started by: alex_5161
1 Replies
Login or Register to Ask a Question