regex - how to parse watch command output to last 5 digits? -


from command

watch -n1 "ifconfig eth0 | grep gib"  

i have output given below,

rx bytes:730624111504 (680.4 gib)  tx bytes:31815434434 (29.6 gib) 

now want last 5 digits before (gib). wrote regex it, , seems work

(\d{1,4})(?!.*\d)\sgib 

the problem cannot use command showed above.

any ideas?

update want

rx bytes:730624111504 (680.4 gib) tx bytes:31815434434 (29.6 gib)

to match rx as

4111504 , 5434434

my regex works in http://www.rubular.com/r/htwfxjcijm not in command

replace grep one:

grep -po '\d{7}(?=\s*\(.*gib)' 

some notes:

  • your example shows not 5 digits, 7
  • you have hardcoded gib in regex, if server rebooted, or network interface down , up, command may not work properly. because starts kib or mib

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -