so number or elements in the array can varies depending on how big the data input is.
now i have a variable, and it is $1 (there are $2, $3 and so on, i am only interested in $1).
in K shell my code would be as follows,
z=0
while [[ $z -lt ${array[*]} ]] ; do
if [[ ${array[$z]} == "$1" ]]
then
print " found a match from list "
let z=$z+1
else
print " no match "
let z=$z+1
fi
done
This works fine in Kshell. However i am editing a scritp that has been written in kshell and AWK. So the part i am working on is written in AWK and AWK doesnt like my while loop. Can someone help me with this please?
This script has 2 funtions. i will post the first part of the code.
#! /usr/bin/ksh
# This script goes through failure logs and prints out a useful
# synopsis of the last failure
# It relies on test log files, console logs, and autotest.result.
. lib.ksh
if [ _$1 = _-all ] ; then
all=1
fi
failures=/tmp/failures.tmp
failLines=/tmp/failLines.tmp
utilFailLines=/tmp/utilFailLines.tmp
miscompareLines=/tmp/miscompareLines.tmp
con=/tmp/con.tmp
failInfo=/tmp/failInfo.tmp
function analyzeConsole
{
# First, cut the console data down to just the part that printed
# out during that test.
# Then run it through termReport.pl.
# Then get the interesting parts of that.
#################################################
# Reading from globallyIgnoredTc list and setting up an array & converting upper case to lower case
file=../data/globallyIgnoredTc.dat
set -A ignore `grep -v "#" ${file} | tr '[A-Z]' '[a-z]' `
#################################################
endMarker="NSC Termination Event Details:"
if [ ! -f $4 ] ; then
echo "No $4 file found. Perhaps testMgr is still running?"
else
# Subtract out a little from the start time. Otherwise we miss
# crashes because of the controller clocks being off by a few seconds.
#dateFilter $4 $(( $2 - 10 )) $3 > $con
# BGL -- analyze all of the consoles. Autotest does the trimming now.
termReport.pl < $4 | dos2ux | head -2000 | awk '
BEGIN { foundTermEvent=0;
endMarker="'"${endMarker}"'"; }
{
if ( (substr($0, 1, length(endMarker)) == endMarker) ||
(substr($0, 1, 39) == "'${SBINDIR}'/termReport.pl: ") )
{
if (foundTermEvent == 1)
{
print "";
foundTermEvent=0;
}
}
##############################################################################
if (foundTermEvent == 1)
{
z=0
while [[ $z -lt ${#ignore
[*]} ]] ; do
if [[ ${ignore[$z]} == "$1" ]] #I want all my array elements to compair against $1. If $1 match with ANY array element, condition is true.
then
print " FOUND A BADTC FROM THE LIST "
foundTermEvent = 0;
print " Z= $z "
echo " ignore[$z] = ${ignore[$z]}"
let z=$z+1
else
#print;
print " DIDNT FIND ANY BAD TCs "
print " Z= $z "
let z=$z+1
fi
done
}
####################################################################
if (substr($0, 1, 18) == "Termination Event:")
{
foundTermEvent=1;
}
}'
fi
}
function analyzeFailure
{
---------- Post updated at 07:14 PM ---------- Previous update was at 07:11 PM ----------
part i get an error is last while loop and the if statement in the while loop. it is complaining about AWK syntax not being correct.
# Current (Shell)
z = 0
while [[ $z -lt ${#ignore[*]} ]] ; do
if [[ ${ignore[$z]} == "$1" ]]; then
print " FOUND A BADTC FROM THE LIST "
foundTermEvent = 0;
print " Z= $z "
echo " ignore[$z] = ${ignore[$z]}"
let z=$z+1
else
print " DIDNT FIND ANY BAD TCs "
print " Z= $z "
let z=$z+1
fi
done
# New (awk)
# Change the line:
# eport.pl < $4 | dos2ux | head -2000 | awk '
# To:
# eport.pl < $4 | dos2ux | head -2000 | paste -sd\| | awk -v S="$1" '
# And the while-loop to:
z = 1
IGNORE = split( $0, IGNORE, "|" )
while( z <= length( IGNORE ) ) {
if( IGNORE[z] == S ) {
print " FOUND A BADTC FROM THE LIST "
foundTermEvent = 0;
print " Z= " z
print "IGNORE[z] = " IGNORE[z]
} else {
print " DIDNT FIND ANY BAD TCs "
}
z++
}