Sponsored Content
Top Forums Shell Programming and Scripting Korn Shell Array maximum value less than other value Post 302528964 by ther2000 on Wednesday 8th of June 2011 09:48:18 AM
Old 06-08-2011
Korn Shell Array maximum value less than other value

I have a text file with several key words that I am trying to isolate. I have grepped for the unknowns in the text file, but each unknown has a corresponding location. I have created an array that holds all the unknowns and another array that holds all of the locations and compares them based on the line number in the report. the locations are always before the unknowns, so I compare positions in the array to check that the location line number is less than the unknown line number. However, the problem is there are multiple locations and multiple unknowns, so if the unknown is above several locations it prints all of those locations whereas I want the closes one. Please see the code:

Code:
 
typeset -i i=0
typeset -i j=0
grep -h -n "LOCATION" $R_FILE | cut -d ':' -f 1 | while read value
do 
arr[i]="$value"
i=$(( $i + 1))
done
 
grep -h -n "unknown" $R_FILE | cut -d ':' -f 1 | while read value
do 
uarr[j]="$value"
j=$(( $j + 1))
done
 
for j in ${uarr[@]}; 
do 
         for i in ${arr[@]};
         do
                         if (($j > $i)) 
                               then 
                                      LOC=$(awk "NR==$i" $R_FILE)
                                      UNK=$(awk "NR==$j" $R_FILE)
                                      print $LOC","$UNK | awk -F"," '{print $1","$2","$4","$5","$3}' >> output 
                         fi
            done
done

Output is as follows:

Code:
LOCATION: M1,19,8300,unknown,
LOCATION: M1,13,eeee,unknown,eooeo
LOCATION: B,13,eeee,unknown,eooeo
LOCATION: M1,5,TICKLISH,unknown,83838388383
LOCATION: B,5,TICKLISH,unknown,83838388383
LOCATION: CL 1-2,5,TICKLISH,unknown,83838388383
LOCATION: CL 1-1,5,TICKLISH,unknown,83838388383
LOCATION: CL 2-2,5,TICKLISH,unknown,83838388383
LOCATION: CL 2-1,5,TICKLISH,unknown,83838388383

Output should be:

Code:
LOCATION: M1,19,8300,unknown,
LOCATION: B,13,eeee,unknown,eooeo
LOCATION: CL 2-1,5,TICKLISH,unknown,83838388383


Last edited by ther2000; 06-08-2011 at 11:13 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Oracle To Korn Shell Array

I'm attempting to populate an array in ksh using the following command: set -A $(SELECT_INVOICE | sed '/^$/d') SELECT_INVOICE is a function that executes the SQL query. Problem: Some of the invoice numbers have alpha characters with spaces(example: OVEN MICRO). The Korn shell is treating... (1 Reply)
Discussion started by: kdst
1 Replies

2. Shell Programming and Scripting

korn shell array?

I read it is possible to provide values for an array with the -A option to the read statement; however, I have not been able to get this to work. When I execute a script with the -A option to the read statement, the shell complains that it is an illegal option. If this works, can someone provide... (5 Replies)
Discussion started by: cstovall
5 Replies

3. UNIX for Dummies Questions & Answers

Maximum Command Length for Korn shell

What is the maximum size of a command which can be given in telnet command prompt in unixfor Korn shell? (2 Replies)
Discussion started by: miltony
2 Replies

4. Shell Programming and Scripting

Unix Korn Shell Array Issue (SunOS)

Hello, I'm currently messing around with arrays for the first time in scripting (Unix Korn Shell). All I'm trying to do right now before I make things complicated is read through and print out to screen whether the read file is or is not a directory. Here is my directory: ls -l total... (5 Replies)
Discussion started by: Janus
5 Replies

5. Shell Programming and Scripting

I can't decalar an array in my korn shell script

I have a script that contains #!/usr/bin/ksh set -A X 'hallo' 'world' echo ${X} echo ${X} when I execute it I get an errror message sh ./test.ksh ./test.ksh: -A: bad option(s) but if I do this at the command prompt I am able to create it set -A myarray '1' '2' '3' echo ${myarray}... (4 Replies)
Discussion started by: zilla30066
4 Replies

6. Shell Programming and Scripting

Could someone give me an example of awk accessing array defined in Korn Shell?

As per title and much apprecieated! (2 Replies)
Discussion started by: biglau
2 Replies

7. Shell Programming and Scripting

need help with korn shell array

I have a korn shell script that reads a file with just one column in the file. If the file has more than 5 entries it is split using split -5. This means that is we have 15 entries I will end up with 3 files with 5 entries/lines in each and if I have 23 entries I will end up with 5 files with the... (2 Replies)
Discussion started by: kieranfoley
2 Replies

8. Shell Programming and Scripting

Generate array name at run time Korn shell

Hi, I am trying to define number of array based on constant derived during execution phase of a script. Here is what i am trying.. #First Part, Get LUN input from User lun_count=4 count=0 set -A my_lun while : do while ]; do read L?"Enter Lun "$count" Number:" ... (2 Replies)
Discussion started by: harris2107
2 Replies

9. Shell Programming and Scripting

'*' vs. '@' in Korn Shell Array Variables

In order to use the shellcurses functions described at: Shell Curses function library I am learning about ksh, which has arrays. My trusty Kochan & Wood book says that for any Korn Shell array AR : ${AR } expands to all the defined array elements, and ${#AR } expands to the number... (3 Replies)
Discussion started by: Clovis_Sangrail
3 Replies

10. Shell Programming and Scripting

How to append to array within conditional block in ksh/korn shell?

Hi, I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement. #!/bin/ksh echo "---------------------------------------------------" set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}'... (2 Replies)
Discussion started by: sanzee007
2 Replies
UNKNOWN(1)						      General Commands Manual							UNKNOWN(1)

NAME
unknown - identify possible genotypes for unknowns SYNOPSIS
A program to rapidly identify which genotypes are possible for individuals typed as unknowns in the input pedigree. unknown [ -cl ] DESCRIPTION
unknown infers possible genotypes and mating combinations for parents with unknown genotypes for ilink(1), mlink(1) and linkmap(1). OPTIONS
-c Use conditional allele frequencies. -l Choose a good set of loop breakers automatically. RETURN VALUE
0 Successful completion ERRORS
10 File not found 255 Failure EXAMPLES
Normally, unknown(1) is run immediately prior to its sister programs, ilink(1), mlink(1) and linkmap(1), like this: unknown mlink FILES
unknown(1) reads the two files pedfile.dat and datafile.dat as its own input and produces various temporary files that are used as input to the next program. These temporary files are ipedfile.dat, upedfile.dat, speedfile.dat and newspeedfile.dat. NOTES
unknown(1) is part of the FASTLINK package, which is a re-implementation of the LINKAGE suite of computer tools that help investigate genetic linkage as first proposed G.M. Lathrop, J.M. Lalouel, C. Julier, and J. Ott. AUTHORS
Dylan Cooper, Alejandro Schaffer, and Tony Schurtz based on work originally by Jurg Ott, Ph.D, et. al. This manual page was written by Elizabeth Barham <lizzy@soggytrousers.net> for the Debian GNU/Linux system (but may be used by others). WORD-WIDE-WEB http://www.ncbi.nlm.nih.gov/CBBResearch/Schaffer/fastlink.html SEE ALSO
ilink(1), linkmap(1), lodscore(1), mlink(1). April 15, 2003 UNKNOWN(1)
All times are GMT -4. The time now is 03:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy