LoginSignup
4
4

More than 5 years have passed since last update.

sedで特定の文字列を抽出

Posted at

[root@localhost ~]# /usr/lib64/nagios/plugins/check_icmp -H 192.168.0.1 > /tmp/a.txt
[root@localhost ~]# 
[root@localhost ~]# cat /tmp/a.txt
OK - 192.168.0.1: rta 0.410ms, lost 0%|rta=0.410ms;200.000;500.000;0; pl=0%;40;80;; rtmax=0.723ms;;;; rtmin=0.180ms;;;;
[root@localhost ~]# 
[root@localhost ~]# cat /tmp/a.txt | sed -r 's/.*rta=([0-9\.]+).*;/\1/'
0.410
[root@localhost ~]# cat /tmp/a.txt | sed -r 's/.*rtmax=([0-9\.]+).*;/\1/'
0.723
[root@localhost ~]# cat /tmp/a.txt | sed -r 's/.*rtmin=([0-9\.]+).*;/\1/'
0.180
[root@localhost ~]#

この例では、Nagiosプラグインのcheck_icmpの実行結果から、
rta、rtmax、rtminの取得値を抽出している。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4