Solved

Korn Shell Problem

Posted on 2002-03-13
3
271 Views
Last Modified: 2010-04-21
I have 2 simple (I think) questions:
1. I am reading in a file which has 3 words in each record. I would like to put each word in a different array e.g. word1 would be in array1 , etc. How could I do that?
2. I am displaying the first word of each record , preceed by a sequence number on the screen e.g.
 1  value1
 2  value2
 3  value3
...
I have done this with the following code:
...
set -A number 1 2 3 4 5 6 7 8 9
...
max=9
i=0
while [[ $i -lt $max ]];do
   line="${number[$i+1]} ${array1[$i]}"
   print $line
   i=$i+1
   done
...
I would like to print the sequence number without having to create the number array, but I have tried various things and nothing seems to work. How could I do that?
0
Comment
Question by:jc31415
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6863705
#! /bin/ksh
integer i = 1
cat your-file |while read array1 array2 array3 ; do
        echo $i $array2
        let i=$i+1
done
0
 

Author Comment

by:jc31415
ID: 6864567
That doesn't solve my problem. I want to move my display forward and backward based on user input. For example I want to display the first 20 entries and then based on user input shift to the next 20 entries and then either forward 20 entries or back 20 entries. So I need the values in an array.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 6864647
#! /bin/ksh
integer i = 1
cat your-file |while read array1[$i] array2[$i] array3[$i] ; do
   let i=$i+1
done

# do mean this?
# no all values from column 1 are in array1, column 2 in array 2, and column 3 in array3
# given an offset for example of 5, you can do:

integer i=5 # or $1 if passed in as first parameter
while [ $i -lt 5+20 ]; do
   echo ${array1[$i]}
done
# keep in mind that there is no check of index to array1
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSH commands for Nas4free 21 499
nodeip 9 92
why my ssh-ldap-helper and ssh-ladp-wrapper files are missing on a new AWS instance? 24 442
reinstall 1 92
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question