繁体   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