Customize the Shell Script output

Hello guys.
about two weeks ago i had a question about customizing output and thanks to you guys i could solve it.
now i have a similar question but this time its little complex.
this is my output:

-------------------+--------------------+---------+---------
ias-component      | process-type       |     pid | status
-------------------+--------------------+---------+---------
DSA                | DSA                |     N/A | Down
LogLoader          | logloaderd         |     N/A | Down
dcm-daemon         | dcm-daemon         |     N/A | Down
OC4J               | home               |   28168 | Alive
OC4J               | home               |   28169 | Alive
OC4J               | home               |   28167 | Down
OC4J               | officeauto         |   12476 | Alive
OC4J               | gaas               |   28170 | Alive
OC4J               | report             |   28172 | Alive
OC4J               | workflow           |    1477 | Alive
OC4J               | messenger          |   28175 | Alive
OC4J               | archive            |   28177 | Alive
OC4J               | GamWS              |   28189 | Alive
OC4J               | sws                |   28108 | Alive
OC4J               | menu               |   28192 | Alive
WebCache           | WebCache           |   27675 | Alive
WebCache           | WebCacheAdmin      |   27671 | Alive
HTTP_Server        | HTTP_Server        |   16552 | Alive

as you can see i have many OC4Js in here and i want to show them like this:

OK|Home=0 Officeauto=1 . . .

for example if all of the home OC4Js were Alive then HomeValue equals to 1 in other wise Homevalue equals to 0.
i wrote this shell script but it didn't work. i know i should use if but i dont know how!

HomeValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /home/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
OfficeautoValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /officeauto/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
ReportValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /report/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
WorkflowValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /workflow/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
MessengerValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /messenger/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
ArchiveValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /archive/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
GamWSValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /GamWS/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
SwsValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /sws/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
MenuValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /menu/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
WebCacheValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /WebCache/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')
HTTP_ServerValue=$("$output" | awk -F\| 'NR>6 && $2 ~ /HTTP_Server/ {gsub (/ /,_);  print $2 "=" ($4=="Alive")}')

echo "OK|Home="$HomeValue" Officeauto="$officeautoValue" Report="$reportValue" Workflow="$workflowValue" Messenger="$messengerValue" Archive="$archiveValue" GamWS"$GamWSValue" Sws="$swsValue" WebCache="$WebCacheValue" HTTP_Server="$HTTP_ServerValue""

---------- Post updated at 07:59 AM ---------- Previous update was at 07:47 AM ----------

i forget something:
the OC4Js count is variable. i mean it completely depends to the server configuration.
Thank you.

I can't imagine how the OC4J comes into play. Not sure if you need the upper case initials, either. However, with output being the file name with your results, try

awk     'NR<=3          {next}
         L[$3]==""      {L[$3]=1}

                        {L[$3]=L[$3] && ($7=="Alive")}

         END            {printf "OK|"
                         for (l in L) printf "%s=%s ", l, L[l]
                         printf "\n"
                        }
        ' output
OK|gaas=1 DSA=0 workflow=1 HTTP_Server=1 home=0 dcm-daemon=0 GamWS=1 officeauto=1 messenger=1 menu=1 archive=1 report=1 sws=1 logloaderd=0 WebCache=1 WebCacheAdmin=1 
1 Like

Thank you dear RudiC. as always your commands worked perfect.
but i really need to do it with upper cases and in my own format.
so would you please help me to correct my code?
Thank you.

Something like this

awk     '
        NR<=3          {next}
         L[$3]==""      {L[$3]=1}

                        {L[$3]=L[$3] && ($7=="Alive")}

         END            {printf "OK|"
                           for  (l in L) {
                                str=l
                                str=toupper(substr(str,1,1)) substr(str,2)
                                printf "%s=%s ", str, L[l]
                                }
                         printf "\n"
                        }
        '  output
# print output:
OK|Gaas=1 Menu=1 Sws=1 Report=1 Officeauto=1 Dcm-daemon=0 Archive=1 Workflow=1 Logloaderd=0 DSA=0 Home=0 HTTP_Server=1 WebCacheAdmin=1 GamWS=1 Messenger=1 WebCache=1