Hi, i am using Solaris ksh shell, i have a file processed from one of the processes as :
List00 contains the objects within it, with rightmost column(i.e 6th column) denoting the state of entire list or the object. I wanted to assign a status to the List00 using a function chkstate () as:
As you can see, i do have a code but its badly optimized. I tried break in if inside awk but that too dint work well for me. Presently i m doing this manually but that's a hectic job to do as i have many such Lists to
analyse. Can someone please help me to optimize the function suited to the constraints, that would be a great help !!!
thanks neutronscott, your code seems to solve most of it, but one logic is missed here. May be one of the constraints was not totally explained, i'll elaborate that again:
your code snippet here, ignores WA state of obj003 and obj004 and returns a NA(implies wrong logic if state = NA after all checks) state if all FW objects are CO(completed)
($1 !~ /^objFW/) {
obj++
if ($NF == "WO") objWO++
if ($NF == "CO") objCO++
}
END {
if (!state) {
if (objCO == obj)
state="Completed"
else if (objWO > 0)
state="InProgress"
else
state="NA"
}
print state
}' "$1"
I myself will try on that but any help from anyone too is very welcome. i think slight tweak in the conditional part will serve the purpose.
here, besides one object working(WO) we have two objects waiting (WA) when all FW objects are completed(CO). Under such a case i must get InProgress state (if any object other than objFW1 and objFW2 is WO then list has a state of InProgress)
Perhaps you are rite. Totally my mistake, after revisiting your code i found there is nothing wrong with the code and is the most elegant solution that can ever be for the situation.
Thanks neutronscott !!!!
All i knew about awk is that it starts with the first field of first record and progresses till the end of record visiting every field only once. But the execution flow in your solution seems different to me(may be i am wrong). Can u briefly explain if my understanding is correct or not ?
Yes. It only processes each line once, going through a file line-by-line. This is why I have variables keep a count of "other objects" CO and WO. The other requirements are pretty much: If you see this one line, then the answer is known definitely. If those first two requirements aren't met, we look at our variables to see if all "other objects" are completed, else, if any "other object" is WO, and finally, fail with NA..
All the code in the END block is executed at those "exit" statements, or after the last line is read in the file.. This is when we decide the state, if one hasn't already been decided.
I was rushed (it's quitting time), feel free to ask for more clarification if needed.