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
Need Help with awk and arrays fusionX Shell Programming and Scripting 7 02-11-2008 06:41 PM
multidimensional array in perl prkfriryce Shell Programming and Scripting 9 12-01-2007 04:33 PM
awk arrays imonthejazz Shell Programming and Scripting 1 09-21-2007 09:29 AM
arrays in awk??? craigsky Shell Programming and Scripting 3 08-27-2007 09:13 PM
KSH and arrays whited05 Shell Programming and Scripting 1 06-24-2005 12:07 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-13-2007
leslie02 leslie02 is offline
Registered User
  
 

Join Date: May 2007
Posts: 5
Question multidimensional arrays

I have a file that's logically in the form of a multidimensional array with an unknown number of records in the file. The file looks like this:

name1
data1
name2
data2
name3
data3
...
nameN
dataN

How do I load this file into an array for processing, while keeping the two relevant lines of data (i.e., name1, data1) together?

I am working in korn shell, no perl available.

Many thanks in advance!
  #2 (permalink)  
Old 07-13-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Leslie,
I do not know the reasons why you want to use two dimensional array,
but here is how you can access both variables:
Code:
while read mStr1
do
  read mStr2
  echo 'Str1 = '${mStr1}' Str2 = '${mStr2}
done < input_file
  #3 (permalink)  
Old 07-13-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Is awk available?

Code:
$ cat infile
name1
data1
name2
data2
name3
data3
$ print ${.sh.version}
Version M-12/28/93d
$ awk '{x[$1]=$2}END{for(i in x)print "index:",i,"element:",x[i]}' <(paste -d" " - -<infile)
index: name1 element: data1
index: name2 element: data2
index: name3 element: data3
For ksh88 use paste -d" " - -<infile|awk ...
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 11:08 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