- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh two dimensional array ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2005 01:32 AM
тАО01-06-2005 01:32 AM
ksh two dimensional array ?
I want to build a two-dimensional array with columns and rows like a spreadsheet and have the rightmost column be a total of each row, and the bottom row be a total of the entire column above it:
.......OS: AIX HP-UX Linux Total
Grp: A 5 10 2 17
B 0 3 9 12
-- -- -- -- --
Tot 5 13 11 29
I have never worked with two-dimensional arrays in ksh. Can you do that?
typeset A [10,10]
A[2,3]=9
- Tags:
- ARRAY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2005 02:09 AM
тАО01-06-2005 02:09 AM
Re: ksh two dimensional array ?
In your example-
ncols=10 ; # specifiy number of columns
p1=2 ; p2=3 ; # Desired position
# Convert position p1,p2 to offset in "A"
let "ix=ncols*(p1-1)+p2"
A[$ix]=9
HTH
-- Rod Hills
(PS - another tool like "perl" might be a better way to go...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-06-2005 02:13 AM
тАО01-06-2005 02:13 AM
Re: ksh two dimensional array ?
Neiter A[2,3] or A[2][3] is valid shell syntax.
Probably the most straightforward approach would be awk --- but it only supports single-dimensional arrays as well BUT awks arrays will work. How can that be? Awk's array indices are associative rather that purely numeric like those of the shell.
This means that X[tom],X[harry], ... are perfectly valid so X[2,3] works as well because "2,3" is treated as a string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-07-2005 01:00 AM
тАО01-07-2005 01:00 AM
Re: ksh two dimensional array ?
Example, with an array a[6,6] and the two indices being i,j ....
The single array a[x] would yield:
x = (i-1) * 6 + j
The only caviat is that the upper limit of one of the indices must be known or arbitrarily set, in this case 6.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2005 01:40 AM
тАО01-10-2005 01:40 AM