Вычитание значения в столбце из другого столбца для некоторых определенных строк только в одном файле - PullRequest
0 голосов
/ 07 декабря 2018

У меня есть файл, который содержит записи для разных IP-адресов.Для одного конкретного IP-адреса 192.168.0.13, показанного в столбце № 29, я хочу вычесть значение в столбце №.40 (т. Е. Время = 25,101) из значения в столбце №2.

, т. Е. 25,1796 минус 25,101.

Слово «время =» в столбце №40 следует удалить до того, как указано выше.вычитание, чтобы иметь место.

Я хочу это вычитание для всех строк, которые содержат IP-адрес только 192.168.0.13.
Файл трассировки вставлен ниже.

t 25.1765 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:1c) ns3::WifiMacTrailer ()
r 25.178 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1598 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.35 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1598 time=25.1142)) Payload (size=244) ns3::WifiMacTrailer ()
t 25.1782 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:25) ns3::WifiMacTrailer ()
r 25.1796 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1597 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.13 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1597 time=25.101)) Payload (size=244) ns3::WifiMacTrailer ()
t 25.1798 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:0f) ns3::WifiMacTrailer ()
r 25.1816 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1588 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.29 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1588 time=24.9821)) Payload (size=244) ns3::WifiMacTrailer ()
t 25.1817 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:1f) ns3::WifiMacTrailer ()
r 25.1856 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1586 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.28 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1586 time=24.9557)) Payload (size=244) ns3::WifiMacTrailer ()
t 25.1858 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:1e) ns3::WifiMacTrailer ()
r 25.1877 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1580 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.37 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1580 time=24.8764)) Payload (size=244) ns3::WifiMacTrailer ()
t 25.1878 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:27) ns3::WifiMacTrailer ()
r 25.1898 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1597 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.5 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1597 time=25.101)) Payload (size=244) ns3::WifiMacTrailer ()
t 25.1899 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:07) ns3::WifiMacTrailer ()
t 25.1906 ns3::WifiMacHeader (EXTENSION_S1G_BEACON ) ns3::S1gBeaconHeader () ns3::WifiMacTrailer ()
r 25.2005 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1558 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.24 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1558 time=24.5857)) Payload (size=244) ns3::WifiMacTrailer ()
t 25.2007 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:1a) ns3::WifiMacTrailer ()
r 25.2156 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1564 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.25 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1564 time=24.665)) Payload (size=244) ns3::WifiMacTrailer ()
t 25.2157 ns3::WifiMacHeader (CTL_ACK Duration/ID=0us, RA=00:00:00:00:00:1b) ns3::WifiMacTrailer ()
r 25.219 ns3::WifiMacHeader (QOSDATA ) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 1581 protocol 17 offset (bytes) 0 flags [none] length: 284 192.168.0.38 > 1.0.0.2) ns3::UdpHeader (length: 264 49153 > 9) ns3::SeqTsHeader ((seq=1581 time=24.8896)) Payload (size=244) ns3::WifiMacTrailer ()

файл трассировки

1 Ответ

0 голосов
/ 07 декабря 2018

Не могли бы вы попробовать один раз (строго учитывая, что ваш фактический Input_file такой же, как показанные образцы).

awk '$29=="192.168.0.13"{gsub(/.*=|\)\)/,"",$40);print $2-$40}'  Input_file

Объяснение вышеприведенного кода:

awk '                      ##Starting awk program here.
$29=="192.168.0.13"{       ##Checking condition if 29th field is same as IP address mentioned by OP if yes then do following.
  gsub(/.*=|\)\)/,"",$40)    ##Using gsub for substituting everything till = AND )) string with NULL here in 40th field since it has value like time=25.101)) and we need only digits to subtract its value.
  print $2-$40             ##Now printing subtraction of $2 and $40 here.
}'  Input_file             ##Mentioning Input_file name here.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...