jc31415
asked on
Korn Shell Problem
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?
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?
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
integer i = 1
cat your-file |while read array1 array2 array3 ; do
echo $i $array2
let i=$i+1
done