INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help with AWK!

Help with AWK!

(OP)
Hello there!

I'm wondering if anyone can help me with this little (big) challenge!

I have a file, with about 30 blocks, each one with the same structure as the following:

---

Timestamp: 14:52:50

+++++ STCP DEVICE METERS +++++

netstat -interface #sdlmux.m5.13.1.0

MAC Type : CSMA/CD
MAC Address: 00:00:a8:43:3f:cd
Device Name: #sdlmux.m5.13.1.0
Line Speed : 100 mb/s
Line Duplex: Full-Duplex

MAC Statistics:
Received frames : 3066396
Received multicast and broadcast frames : 102
Received octets : 813041981
Transmitted frames : 3430870
Transmitted octets : 1220638884
LAN Chipset re-initialized : 0
SQE error : 0
Transmit ring full : 0
Transmit frame discarded, late collisions: 0
Transmit frame was deferred : 0
Transmit frame after a single retry : 0
Transmit frame after multiple retry : 0
Transmit frame discarded, excessive retry: 0
Receive frame discarded, lack of buffers : 0
Receive frame discarded, improper framing: 0
Receive frame discarded, an overflow : 0
Receive frame discarded, bad CRC : 0
Receive frame discarded, bad address : 0
Receive frame discarded, congestion : 0

MAC Summary:
Transmitted frames : 3430870
Transmitted octets : 1220638884
Retransmitted frames : 0
Received frames : 3066498
Received octets : 813041981
Total of lost frames : 0
ready 18:52:49


***** END OF RECORD *****


I'm wondering if there's a way to use AWK (and SED) to get the values above in red, and put them in a line, separated with comma... like this:

Timestamp , device_name , received_frame , received_multicast , received_octets , transmitted_frames , transmitted_octets , Receive_frame_bad_crc

This is getting me nuts. I have to get the line for every block in the text file, and I can't use the awk to get the column values, because it's not allways the same.

Anyone can help me?

Thanks!!!

RE: Help with AWK!

Something like this should do the trick, I'll leave you to fill in the dots.

CODE --> awk

awk '
    /^Device Name/ { dev=$NF }
    /^Timestamp/ { ts=$NF }
    /^Received Frames/ { rf=$NF }
    # ...
    / END OF RECORD / {
        print ts, dev, rf # ...
    }
' inputfile 

If any of the device names contain spaces you may need to do something a little more clever than using $NF (which means the last field on the line) to capture them.

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close