I have a need to to parse a source file which is a capture from a network analyser.
I have two fields that need to be checked:
Field 7 represents the packet length (an integer), and
Field 4 represents a network address (e.g. 192.168.25.3)
The first check is to find 2 consecutive lines that have the same integer in Field 7 i.e. the same length. Original file may not always have these lines consecutive though, but I am ok to ignore those lines if it is too difficult to include those.
Then, once we have these two lines, check the text in Field 4 for these lines and inidicate the value within the text that is 'first' and increment a variable.
What I'm after is to understand how many times address A is first compared to address B.
My expected output from the sample below would be:
"239.25.30.25 is first once" and "239.25.30.26 is first twice.
Even an output like "239.25.30.25 - 1, 239.25.30.26 - 2" would be great.
To answer your question, I have a text file containing data from a network capture.
The data is duplicated (on purpose) and is sent to two destinations (multicast addresses). Sometimes data for one destination is received first, other times data to the other destination is first.
I'm trying to work out which destination is usually first depending on the sample I capture.
I've just seen that depending on which awk string I run from the replies above, I get different output / results from the replies received, so will probably still need to verify which gives me the most correct answer for a particular sample.
I think cambridge's script works best for me so far.
Note that my script only works with consecutive lines. It gets more convoluted if you want to handle other cases, as you'll need to decide how many lines should be allowed between each for it to be a valid sample.
I'm trying to understand better what your script does so I can manipulate it to do an additional check on the first field (I want to ensure the lines been compared have the first field within 5 integers of each other).
I'd like to work it out myself, but just need a bit of help with understanding the syntax below...
I'm setting the variable 'last' to the value in the 12th field, but only if I've not set this variable before or if the variable contains the value 0. That's what 'if (!last)' means, if the 'last' variable is blank or 0. In AWK, if you reference a variable that's never been set before, it's the same as if it were blank or 0.
Well ipc is an associative array. The key is the 'ip' variable set earlier. Yes, we're maintaining counters for each unique IP address we come across where the 12th field is the same on two consecutive lines, and this is where that counter is incremented.