2017-05-07 45 views
0

我有一個腳本,輸出以下輸出:正確管道輸入到grep和在其上對位執行正則表達式和匹配的字符串

總體狀態 - 行(採樣週期9秒) - 物理驅動器名稱=」 0 C:「(OK)_PercentIdleTime = 100%_PercentBusyTime = 0% _PercentDiskTime = 1%_PercentDiskReadTime = 0%_PercentDiskWriteTime = 1%_DiskReadBytesPersec = 0.000B/sec _DiskReadsPersec = 0.000/sec _DiskWriteBytesPersec = 0.00MB/sec,_DiskWritesPersec = 8.000/sec,CurrentDiskQueueLength = 0,_AvgDiskQueueLength = 0.0,_AvgDiskReadQueueLength = 0.0,_AvgDiskWriteQueueLength = 0.0 |'_PercentIdleTime0 C:'= 100; '_PercentBusyTime0 C:'= 0; '_PercentDiskTime0 C:'= 1; '_PercentDiskReadTime0 C:'= 0; '_PercentDiskWriteTime0 C:'= 1; '_DiskReadBytesPersec0 C:'= 0; '_DiskReadsPersec0 C:'= 0; '_DiskWriteBytesPersec0 C:'= 71917; '_DiskWritesPersec0 C:'= 8; 'CurrentDiskQueueLength0 C:'= 0; '_AvgDiskQueueLength0 C:'= 0.0; '_AvgDiskReadQueueLength0 C:'= 0.0; '_AvgDiskWriteQueueLength0 C:'= 0.0;

使用grep我想過濾掉一切,但_DiskWriteBytesPersec = 0.00MB

我用下面的正則表達式上http://regexr.com/成功地這樣做: (_DiskWriteBytesPersec =(\ d *)? 。(\ d *)MB)

但我很難讓它與grep一起工作。

+0

請看看[editing-help](http://stackoverflow.com/editing-help)。 – Cyrus

回答

0

問題與你的正則表達式是(_DiskWriteBytesPersec=(\d*)?.(\d*)MB),它不支持\d而不是使用[0-9],你可以試試這個,它會正常工作。

echo "Overall Status - OK (Sample Period 9 sec) - Physical Drive Name="0 C:" (OK) - _PercentIdleTime=100%, _PercentBusyTime=0%, _PercentDiskTime=1%, _PercentDiskReadTime=0%, _PercentDiskWriteTime=1%, _DiskReadBytesPersec=0.000B/sec, _DiskReadsPersec=0.000/sec, _DiskWriteBytesPersec=0.00MB/sec, _DiskWritesPersec=8.000/sec, CurrentDiskQueueLength=0, _AvgDiskQueueLength=0.0, _AvgDiskReadQueueLength=0.0, _AvgDiskWriteQueueLength=0.0|'_PercentIdleTime0 C:'=100; '_PercentBusyTime0 C:'=0; '_PercentDiskTime0 C:'=1; '_PercentDiskReadTime0 C:'=0; '_PercentDiskWriteTime0 C:'=1; '_DiskReadBytesPersec0 C:'=0; '_DiskReadsPersec0 C:'=0; '_DiskWriteBytesPersec0 C:'=71917; '_DiskWritesPersec0 C:'=8; 'CurrentDiskQueueLength0 C:'=0; '_AvgDiskQueueLength0 C:'=0.0; '_AvgDiskReadQueueLength0 C:'=0.0; '_AvgDiskWriteQueueLength0 C:'=0.0;" | grep -Eo "_DiskWriteBytesPersec=[0-9]*?.[0-9]+MB"; 

管與grep -Eo "_DiskWriteBytesPersec=[0-9]*?.[0-9]+MB"

命令輸出的輸出:_DiskWriteBytesPersec=0.00MB

E的擴展正則表達式。

2.O僅輸出匹配的字符串。

相關問題