Kamis, 11 Desember 2008

Belajar Awk

Saya ingin mengambil angka hasil melakukan ping. Untuk itu saya perlu melakukan parsing dari hasil yang muncul.

Melakukan ping 5 kali
$ ping -c 5 localhost
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.092 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.071 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.069 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.067 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.060 ms

Lalu saya ambil urutan (urutan ke-6) berikut response time (urutan ke-8)
$ ping -c 5 localhost | awk '{print $6 " " $8}'
of
icmp_seq=1 time=0.070
icmp_seq=2 time=0.089
icmp_seq=3 time=0.085
icmp_seq=4 time=0.064
icmp_seq=5 time=0.090


0% loss,

Dilanjutkan lagi, ambil angkanya saja
$ ....

1 komentar:

za mengatakan...

Untuk memotong gunakan perintah cut

$ ping -c 5 localhost | awk '{print $6 " " $8}' | cut -f 3 -d "="