Awk help with source and previous line loop

Hello,

I've written a ksh awk script to ping multiple servers and write the results to a file. That part is working ok. I then want to extract the names of only the server which are available. This is indicated by '1 packets received'. The server name actually appears above that line so I found a command that finds source data and prints the line above as well.
Anyway to cut a long story short the script is only finding the first available server and not the rest. My source file looks like:

--- serv001 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss PING serv001 (xx.xx.xxx.xx): 56 data bytes
--- serv002 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss PING serv002 (xx.xx.xxx.xx): 56 data bytes
64 bytes from xx.x.xx.xx: icmp_seq=0 ttl=254 time=0 ms
--- serv003 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0/0/0 ms PING server003 (xxx.xx.xxx.xx): 56 data bytes
--- server004 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss PING server004 (xx.xx.xxx.x): 56 data bytes
--- server005 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss PING 
server005 (xx.xx.x.xx): 56 data bytes
--- server006 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0/0/0 ms PING server006 (xx.xx.xx.xx): 56 data bytes

the code is:

cat pingy99 | awk 'NR==1{str=$0}$0~/1 packets received,/{ print str,$0}'>p77

echo The following servers are available:
cat p77

but this only shows the first server found (server3)

Sorry for such a long post but I suppose the bottom line question is:

How do I get the awk to read and report on the entire source file?

Any help appreciated

Something like this?

awk '/1 packets received/{print p RS $0}{p=$0}' pingy99

Cheers Franklin that worked fine.

If you get a moment could you break down the command for me. I'm still new to awk!

Sure :):

awk '/1 packets received/{print p RS $0}{p=$0}'

Explanation:

/1 packets received/{print p RS $0}

If the current line matches the pattern /1 packets received/ print the previous line p a record separator and the current line. Notice that the variable p still holds the previous line.

{p=$0}

Store the current line in the variable p.

Cheers really appreciate that