-4

I want to measure time between transmitted and received packets in below trace file.

Input:

 + 0.01 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Enqueue
 - 0.01 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Dequeue
 r 0.0200001 /NodeList/0/DeviceList/2/$ns3::PointToPointNetDevice/MacRx
 + 0.11 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Enqueue
 - 0.11 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Dequeue
 r 0.12 /NodeList/0/DeviceList/2/$ns3::PointToPointNetDevice/MacRx
 + 0.12 /NodeList/0/DeviceList/3/$ns3::PointToPointNetDevice/TxQueue/Enqueue
 - 0.12 /NodeList/0/DeviceList/3/$ns3::PointToPointNetDevice/TxQueue/Dequeue
 r 0.120001 /NodeList/2/DeviceList/2/$ns3::PointToPointNetDevice/MacRx

Here + represents transmitted data and r represents received data. 2nd column in the trace file shows the time.

How can I measure time between r and + for the whole file using awk code?

The expected output can be as below:

Output:

  0.0100001
  0.01
  0.000001

I'll be grateful if anyone helps.

josef
  • 3
  • 3
  • [edit] your question to include concise, testable sample input and expected output. If you need an external site to show it then you haven't put the effort into making it Minimal (as in [mcve]). – Ed Morton Jan 31 '17 at 23:11

1 Answers1

1

I generated my own trace file, called trace, as follows:

+ 0.1 Stuff stuff and more stuff
- 0.2 Yet more stuff
r 0.4 Something new
+ 0.8 Something else, not so new
- 1.6 Jiggery
r 3.2 Pokery
+ 6.4 Higgledy Piggledy

Then, I would approach your question with awk as follows:

awk '/^+/{tx=$2}  /^r/{rx=$2; d=rx-tx; $1=$1 "(d=" d ")"} 1' trace

Sample Output

+ 0.1 Stuff stuff and more stuff
- 0.2 Yet more stuff
r(d=0.3) 0.4 Something new
+ 0.8 Something else, not so new
- 1.6 Jiggery
r(d=2.4) 3.2 Pokery
+ 6.4 Higgledy Piggledy

That says... "If you see a line starting with +, save the second field as variable tx. If you see a line starting with r, save the second field as variable rx. Calculate the difference between rx and tx and save it as d. Rebuild the first field of the line by appending (d=variable d) to the end of whatever it was. The 1 at the end tells awk to do its natural thing - i.e. print the line."

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thanks a lot for your effort to explain in such a way. – josef Feb 01 '17 at 13:44
  • I just tried this code and it didn't work. It's saying that the regular expression compile failed (syntax error ^* or ^+), and even if I try to fix that by putting a / in front of the +, it still says that there's a syntax error at or near a {. – nick012000 Oct 08 '19 at 03:12
  • 1
    @nick012000 Maybe ask a new question showing a sample of your data as things may have changed in 2 years. Questions are free. Click `share` under this answer and it will give you a link you can add to your new question to refer back to this one. – Mark Setchell Oct 08 '19 at 06:21
  • @MarkSetchell I might do that tomorrow. – nick012000 Oct 08 '19 at 06:54