Array and Selection


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Array and Selection
# 1  
Old 07-12-2007
Array and Selection

I have a question:

Y X
Tabel a is a array multidimensional --> a(1024,20)

I load in to array a Text from 6000 row where:
in a(1,1) is present the row 1 of original text, in a(1024,1) is present then row 1024 of original test and in a(1024,2) is present the row 2048 of original text , in a(1,3) is present the row 2049 the ooriginal text ecc....

fig.

1 2 3 4 (X array)

1

.. > ( Y array)

..

...

1024 1024 1024 1024



I find a procedure / function to point a cell(x,y) where in input are the l row of original text loaded.

es function Position (row Y, column x)

-- solve --

POSFOUND=xxxxxx in the original text.

and
function PosArray ( roworiginal x )
Rowxres and Columres return the array position

tanks
# 2  
Old 07-12-2007
Remember !!!!

I use Posix shell (ksh)

tanks
# 3  
Old 07-12-2007
I'm not sure I follow you. But here is an attempt at what I think you may want:
Code:
#! /usr/bin/ksh

nline=0
while read line ; do
        ((element=nline%1000))
        ((narray=nline/1000))
        eval array${narray}[$element]=\$line
        ((nline=nline+1))
done < bigfile
((count=narray*1000+element))




while echo enter x,y \\c  ; read  x y ; do
        echo x = $x
        echo y = $y

        ((lineno=(y-1)*1024+x))
        echo lineno = $lineno
        ((element=(lineno-1)%1000))
        ((narray=(lineno-1)/1000))
        echo element = $element
        echo narray = $narray
        eval value=\"\${array${narray}[$element]}\"
        echo value = $value
done
echo
exit 0

The first paragraph just reads a file into a very large array. Ideally, I would use a 6000 element array. But ksh does not guarantee that arrays that large will work. So I use a collection of arrays, each with 1000 elements. To access element 1234, I use real element 234 of array 1. Then I have a loop that reads coordinates and calculates the line number coresponding to those coordinates. Then I convert the line number to array/element and grab the value. To test it, I created a bigfile with:
yes | awk '{print NR,$0}' | sed 6000q > bigfile
# 4  
Old 07-15-2007
how you declare a collection of array ???

why in you procedure not use the sintax Array[x,y] but eval array${narray}[$element]=\$line ???


very taks
# 5  
Old 07-15-2007
You just start using an array, no need to "declare" it. ksh does not have multi-dimensioned arrays. It only has one dimensional arrays. So I had to improvise.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selection from array

Hi, I need some help taking a selection from a command and adding part of the output to an array. I'd like to read the items into the array, have the user chose an option from the array and put the item from column 1 into a variable. The command is: awless -l list routetables --columns... (7 Replies)
Discussion started by: bignellrp
7 Replies

2. Shell Programming and Scripting

If Selection statement

ok im kinda stuck i have a bash script with 4 options 1. Create Script 2. Show Script 3 . Delete script 4. Exithow would i use an if statement for this? im not sure what test command i would use. I know it would be like this (below) to display the script if then cat script1or for the... (10 Replies)
Discussion started by: gangsta
10 Replies

3. Shell Programming and Scripting

Date selection

Hi All, i have log file sample data is 2010/10/09|04:00:00.392|15Minute|BW=0|192.168.0.1 2010/10/08|04:00:00.392|15Minute|BW=0|192.168.0.1 2010/10/07|04:00:00.392|15Minute|BW=0|192.168.0.1 2010/10/05|04:00:00.392|15Minute|BW=0|192.168.0.1 2010/10/03|04:00:00.392|15Minute|BW=0|192.168.0.1... (2 Replies)
Discussion started by: posner
2 Replies

4. UNIX for Dummies Questions & Answers

awk for column selection

Hello, I want to extract all values from table except for those that contain the '*' character in the second column. I tried awk '$2!=*' and this threw a syntax error. Do I need to specify an escape character or != is valid only for numerical comparisons? Thanks, Guss (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

5. AIX

Bulk Fixes Selection

Under smit, one has to manually select each fix with F7. there 9000 fixes left to be marked. How Can I manually install/Mark all of these without SMIT. ---------- Post updated at 02:29 PM ---------- Previous update was at 01:15 PM ---------- From the command line instfix -T -d... (4 Replies)
Discussion started by: mrmurdock
4 Replies

6. Shell Programming and Scripting

Data selection

Hi, Please note that as a programmer I cannot tell the file format or details of my production files so I have re-framed my file and taken a case of departments. Kindly guide as its related to a production requirement of data containing recors of production customer NOT A HOMEWORK :) I have... (10 Replies)
Discussion started by: test_user
10 Replies

7. Shell Programming and Scripting

Data selection

Hi, I have a file containing details of different departments . Infomration of departments is in various tags file is as below I want to create a new file from the above file which should contain only two fields belonging to one department format There are multiple files... (1 Reply)
Discussion started by: test_user
1 Replies

8. Shell Programming and Scripting

Menu help with array selection

Hi there all I got the following I got multiple arrays named for example STAT_AAAA STAT_AAAB STAT_AAAC STAT_AAAD Now what I want I have chosen an option in a menu to select 1 but I dont want to write for all the same thing so I made it a signle one now what I want is to get STAT_ and... (6 Replies)
Discussion started by: draco
6 Replies

9. Post Here to Contact Site Administrators and Moderators

Opt out selection

Maybe I'm missing something but when I go to CP->Options, I see the box for selecting which forum to opt out of but no way to set it. (5 Replies)
Discussion started by: drhowarddrfine
5 Replies

10. UNIX for Advanced & Expert Users

tray selection

Hello All, Could anyone help me how to selecting the trays in unix . Thanks, Amit kul (3 Replies)
Discussion started by: amit kul
3 Replies
Login or Register to Ask a Question