create an array of numbers in awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers create an array of numbers in awk
# 1  
Old 04-08-2012
create an array of numbers in awk

Hi !

I try to create an array of a large amount of numbers in increasing order from 1 to 10,000 (or even infinity).

Is there an easier way to do that than writing:
Code:
split("1,2,3,4,5,6,7,8,9,10,11,12,13,14,..............,10000",numbers,",")

Doing something like:
Code:
split([1-10000],numbers)

Thanks !
# 2  
Old 04-08-2012
I guess you have your reasons, but I don't see the point of an array of sequential numbers.

Code:
awk '
   BEGIN {
      for( i = 1; i <= 10000; i++ )
         numbers[i] = i;
   }

This User Gave Thanks to agama For This Post:
# 3  
Old 04-08-2012
You're absolutely right !

Thanks agama
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

2. Shell Programming and Scripting

How to create individual entries from a range of numbers?

I want to create entries based on the series as in examples below: Input: 2dat3 grht-5&&-15 3dat3 grht-16&&-30 4dat3 ftht-4&&-12 5sat3 ftht-16&&-20 Output: 2dat3 grht-5 2dat3 grht-6 2dat3 grht-7 2dat3 grht-8 (7 Replies)
Discussion started by: aydj
7 Replies

3. Programming

generate array of random numbers

hi guys, I am writing a c program that generates a two dimensional array to make matrix and a vector of random numbers and perform multiplication. I can't figure out whats wrong with my code. It generates a matrix of random numbers but all the numbers in the vector array is same and so is the... (2 Replies)
Discussion started by: saboture88
2 Replies

4. UNIX for Dummies Questions & Answers

Help with printing sorted array of numbers

Dear All, I am trying to sort an array of numbers to retrieve the mimimum and maximum values of numbers in that array, by printing the first and last elements of the sorted array. My code is @sorted_numbers = sort (@numbers); print "@sorted_numbers\n"; print "$sorted_numbers,... (0 Replies)
Discussion started by: pawannoel
0 Replies

5. Shell Programming and Scripting

Loop assistance, getting array of random numbers and feeding to a command, how-to?

Hi all, I need a little assistance to complete the following script. I would like to take a file with a single number on each line and for each number, run it through a command. The loop will terminate once all numbers have been checked. Here is what I have thus far... COUNTER=`wc -l... (2 Replies)
Discussion started by: boolean2222
2 Replies

6. UNIX for Dummies Questions & Answers

Create an array with awk

List, I want to have an array created of a particular item in the following textfile: router> show user Se4/0:29 site1 Sync PPP - Bundle: Di372 Se5/0:29 site2 Sync PPP - Bundle: Di340 router> The array should have 2 entries, site1 and site2 ... (2 Replies)
Discussion started by: philipz
2 Replies

7. Solaris

can array store float point numbers

Hi all, I have doubt can array in a shell script can store floating point numbers. i have tired. but i unable to work it out. Please help me regarding this Thank U Naree (1 Reply)
Discussion started by: naree
1 Replies

8. Solaris

i cannot assign float point numbers to an array in solaris

total=0 declare -a sum limit=`iostat -En | grep -i size | awk '{print $2}' | sed -e 's/GB//g' | wc -l` echo "Limit is equal to $limit" ara="`iostat -En | grep -i size | awk '{print $2}' | sed -e 's/GB//g'`" for (( i=1; i<=$limit; i++ )) do sum=`echo $ara | cut -d " " -f $i` echo ${sum}... (11 Replies)
Discussion started by: naree
11 Replies

9. Shell Programming and Scripting

create array holding characters from sring then echo array.

Hi, I wish to store $string1 in $string1array a character in each array element. Then i wish to echo the entire array to the screen so that it reads as the normal string again. I have been trying with the code below but does not work. Please help... To put string into array: ... (5 Replies)
Discussion started by: rorey_breaker
5 Replies
Login or Register to Ask a Question