Skip to content
Advertisement

manipulate column fields for clean representation

Hi I have data in txt file in following format

TCP dmz 10.20.10.144:8080 inside 10.1.1.98:59217, idle 0:00:11, bytes 1295, flags UFRIO
TCP dmz 10.20.10.144:8082 inside 10.1.1.98:31949, idle 0:00:13, bytes 956, flags UfrIO
TCP dmz 10.20.10.144:8082 inside 10.1.1.97:60194, idle 0:00:16, bytes 645, flags UfrIO

I want to only extract

IP address and bytes field, so final result should be

10.20.10.144 10.1.1.98 1295
10.20.10.144 10.1.1.98 956
10.20.10.144 10.1.1.97 645

Also at the end i want to group by bytes (3rd column) by first field. to get :

10.20.10.144 2896

Any help ?

thanks

Advertisement

Answer

If you want to consider awk:

awk -F '[ ,]' '{sub(/:.+$/, "", $3); sub(/:.+$/, "", $5); print $3, $5, $11}' file
10.20.10.144 10.1.1.98 1295
10.20.10.144 10.1.1.98 956
10.20.10.144 10.1.1.97 645

EDIT: Based on comments below:

awk -F '[ ,]' '{sub(/:.+$/, "", $3); a[$3]+=$11} END{for (i in a) print i, a[i]}' file
10.20.10.144 2896
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement