简体   繁体   中英

python bash commands with awk

Can anybody help me to use awk command from python script in order to parse the data from that file

#!/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")

value in file

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";}'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM