簡體   English   中英

帶有awk的python bash命令

[英]python bash commands with awk

任何人都可以幫助我使用python腳本中的awk命令來解析該文件中的數據

#!/usr/bin/python3
import os
os.system ([cat mylog2017-10-29.log |grep OCS0 |cut -c1-21 |sort |uniq -c |awk '$1 >500'])
if $1 > 501:
 print ("TPS is High")
else :
  print ("TPS is low")

文件中的值

ravi@DESKTOP-GC5TPQV:/mnt/c/ubuntu/bash/shellscripts/log$ cat mylog2017-10-29.log |grep OCS0 |cut -c1-21 |sort |uniq -c |awk '$1 >500'
    892 29 Oct 2017 00:00:00,
    540 29 Oct 2017 00:00:02,
    670 29 Oct 2017 00:15:01,
    536 29 Oct 2017 00:17:22,
    502 29 Oct 2017 00:27:58,
    844 29 Oct 2017 00:30:02,
    604 29 Oct 2017 00:43:00,
    646 29 Oct 2017 00:45:03,
    522 29 Oct 2017 00:58:01,
    600 29 Oct 2017 01:00:04,
   1161 29 Oct 2017 20:13:18,
 ----------------------------------------------------------



  File "./tps.py", line 5
    os.system ([cat mylog2017-10-29.log |grep OCS0 |cut -c1-21 |sort |uniq -c |awk '$1 >500'])
                           ^
SyntaxError: invalid syntax
ravi@DESKTOP-GC5TPQV:/mnt/c/ubuntu/bash/shellscripts/log$   

您將必須通過以下方式重寫系統命令調用:

os.system ([cat mylog2017-10-29.log |grep OCS0 |cut -c1-21 |sort |uniq -c | awk '{if($1 > 501)print "TPS is High";else print"TPS is low";}'])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM