Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Packets and Perl

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi
I have a text file that looks like this

Link encap:Ethernet HWaddr 00:00:B4:44:E2:4B
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::200:b4ff:fe44:e24b/10 Scope:Link
inet6 addr: fe80::b444:e24b/10 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:26336217 errors:0 dropped:166 overruns:0 frame:2554
TX packets:26793895 errors:0 dropped:0 overruns:0 carrier:0
collisions:70878 txqueuelen:100
RX bytes:981223126 (935.7 Mb) TX bytes:4191645335 (3997.4 Mb)
Interrupt:10 Base address:0x260

What is the diffrent between RX bytes and TX bytes ??

The next question is how to grep 2 values in the file

Line 9 looks like this

RX bytes:981223126 (935.7 Mb) TX bytes:4191645335 (3997.4 Mb)

How can I grep the RX bytes value 981223126, (yes it will be diffrent each time) and I also want to grep the TX bytes value 4191645335

It's just the long value I want to grep, not the (xxxx) value.

Thanks
//Fredrik
 
RX is Received data and TX is transmitted data. Sorry I can't help you with grep.
 
grep question:

tail -n 2 file2.txt | grep RX | cut -d: -f 2 | cut -d\ -f 1
This gives you the RX information

tail -n 2 file2.txt | grep RX | cut -d: -f 3 | cut -d\ -f 1
This gives you the TX information

These commands assume that the RX & TX line is the second to last line. If this is not the case, change the first number (2 in this case) to X (where X is the number of lines from the bottom of the file where the information is).

Also note that there IS a double space after the \ in the last cut command.

Hope this helps. AV
tnedor@yahoo.com

Did this post help? Click below to let me know.
 
Little script gives you all interface RX stats.
The problem with cut and that ilk is like tnedor remarks:
There is a problem with the format of the i/o data:
it cannot be anticipated and the code is kludged.
This fixes that.
However, it could use something like a function
to determine interface for the RX packets listed
(probably could use /proc more easily for this)

/sbin/ifconfig | awk ' {
if ($0 ~ /RX packets/) {
i = $0
}
split(i,arr,/errors.*/)

for (x in arr) {
print arr[x]
}
}' | sort -u

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top