Using AWK to format missing rows from Netstat output

I'm having issues trying to create an AWK script which will fill in the missing rows from a file generated from Netstat and output to a new file

the Netstat output that I have captured has missing rows if no connection is made during that time period ...

for example

20200531170036
   5 CLOSE_WAIT
349 ESTABLISHED
   5 FIN_WAIT_2
   1 TIME_WAIT
20200531170042
   5 CLOSE_WAIT
356 ESTABLISHED
   5 FIN_WAIT_2
20200531170047
   4 CLOSE_WAIT
360 ESTABLISHED
   2 TIME_WAIT

so I'd want it to display any missing rows with a 0 (see items in bold below )

Moderator : Now with code tags, required output change is enclosed with **, instead of bold.

20200531170036
   5 CLOSE_WAIT
349 ESTABLISHED
   5 FIN_WAIT_2
   1 TIME_WAIT
20200531170042
   5 CLOSE_WAIT
356 ESTABLISHED
   5 FIN_WAIT_2
   **0 TIME_WAIT**
20200531170047
   4 CLOSE_WAIT
360 ESTABLISHED
   **0 FIN_WAIT_2**
   2 TIME_WAIT

so always displaying CLOSE_WAIT, ESTABLISHED, FIN_WAIT_2, TIME_WAIT on separate rows

Any suggestions how I can get this to work using AWK ?

many thanks

Welcome to the forums!

Any attempts / code from your side to solve the problem at hand ?
We encourage users to show us their work first, then we can help improve or rewrite it.

Regards
Peasant.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.