The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk selection on fields amatuer_lee_3 Shell Programming and Scripting 3 05-13-2008 01:05 AM
Opt out selection drhowarddrfine Post Here to Contact Site Administrators and Moderators 5 01-24-2008 02:20 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 08:42 AM
tray selection amit kul UNIX for Advanced & Expert Users 3 07-16-2007 08:31 AM
Character selection script Ypnos Shell Programming and Scripting 2 11-20-2003 01:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-12-2007
ZINGARO ZINGARO is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 36
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 (permalink)  
Old 07-12-2007
ZINGARO ZINGARO is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 36
Remember !!!!

I use Posix shell (ksh)

tanks
  #3 (permalink)  
Old 07-12-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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 (permalink)  
Old 07-15-2007
ZINGARO ZINGARO is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 36
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 (permalink)  
Old 07-15-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0