Question

I am new to bash/awk programming and need your help soon

This is hexadecimal ouptut of an ipv6 tcp packet captured through tcpdump -

 6000 0000 0018 0620 0000 0000
 0000 0000 0000 0000 0000 0001 0000 0000
 0000 0000 0000 0000 0000 0002 *0026 0026
 0000 0001 0000 0002 {5}412 0065 0034 0000*
 6162 6364    

The {5} specify the tcp packet length in 32-bit words and tcp packet is b/w *s.

 (* and {} are used to clear the question ,they are not 
  present actually in output)

Now I need to extract tcp header from this info using bash/awk script.

I think I need to read file byte by byte upto tcp specified length but don't know how to do this.

So any idea how can I extract tcp information from the output specified above assume It has been written in a file.

Thanx in advance ..

Was it helpful?

Solution

Use the awk feature that allows you to set what characters are used for the RecordSeparator (RS) and OutputRecordSeperator (ORS), and use the NumberRecord (NR) var to monitor which part of the rec you print.

awk '{BEGIN RS=" ";ORS="\n";} { if (NR >20 && NR < 31) print $0}' hexFile

If you give more detail about your file (how does repeating sets of this data look?) and expected output, I can probably make this even more efficient for you.

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top