0

I have tables like this in a log file. I am looking for a way to grab out certain lines and add a sentence behind it relating to my server that it was down in within my unix box. Is that possible ?

If I use this command I can get the all the DOWNs on my table "grep DOWN file" now I also want which mdserver it was down at also. My first thought was to use the -B switch in grep to do this. However that isn't going to work as mdserver* can't be expected certain lines above the "DOWN" item. Any suggestions ? Thank you.

My table in log file

mdserver10
Corn    UP  0   0 
Bacon   UP  54  0 
Water   DOWN    0   0 
Fries   UP  746     0 
Turkey  UP  0   
mdserver11
Water   DOWN    0   0 
Fries   UP  746     0 
Turkey  UP  0    
mdserver12
Corn    DOWN    0   0 
Bacon   UP  54  0 
Water   UP  0   0 
Fries   UP  746     0 

My expected results.

Water   DOWN    0   0 is down on mdserver10
Water   DOWN    0   0 is down on mdserver11
Corn    DOWN    0   0 is down on mdnserver12

</table><table border="1" style="width:300px">mdserver10 </tr>
<tr><td style="width:310px"> Water     </td><td bgcolor ="red"> DOWN   </td><td style="width:50px"> 0            </td><td style="width:50px">  </tr>          </td></tr>
LinA
  • 19
  • 6

1 Answers1

2
$ awk 'NF==1{srvr=$0; next} /DOWN/{print $0, "is down on", srvr}' file
Water   DOWN    0   0 is down on mdserver10
Water   DOWN    0   0 is down on mdserver11
Corn    DOWN    0   0 is down on mdserver12
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
  • It work in my example instants but not on my actual production example because I have html codes in in the lines as well. is there a way to edit that code so it works on these lines ? Thank you. I added the lines in my question. – LinA Nov 05 '14 at 21:09
  • What I meant is I want the full line "mdserver10 " inorder to create the table for reporting. not just mdserver10. i thought the same case would apply but it seems not to ...
    – LinA Nov 05 '14 at 21:26
  • I don't know if you're saying your input contains HTML or you want HTML to appear in your output or both and I don't know if your output is supposed to be the plain text table followed by HTML as you show or something else. Please edit your question to provide clear, precise, truly representative input and the associated output. – Ed Morton Nov 06 '14 at 00:35