大家好我这个脚本有问题。我刚刚开始研究它,它应该寻找以前由我制作的另一个脚本生成的条目。
事情的要点是日志的条目如下:
#! /usr/bin/python
import sys,json,requests
from requests.auth import HTTPBasicAuth
# static variables
URL=''
USER_NAME=''
PASSWORD=''
# returns avg value
def getAvg():
query = json.dumps({
"aggs": {
"single_avg_price": {
"avg": {
"field": "price"
}
}
}
})
response = requests.get(URL,auth=HTTPBasicAuth(USER_NAME,PASSWORD), data=query)
results = json.loads(response.text)
return results['aggregations']['single_avg_price']['value']
#returns rows that are greater than avg value
def rows_greater_than_avg(avg_value):
query = json.dumps({
"query" : {
"range": {
"price": {
"gte":avg_value
}
}
}
})
response = requests.get(URL,auth=HTTPBasicAuth(USER_NAME,PASSWORD), data=query)
results = json.loads(response.text)
return results
# main method
def main():
avg_value = getAvg()
print( rows_greater_than_avg(avg_value))
main()
格式为 filename_inode:/ originaldirectory /
这个脚本应该带一个参数并在日志中查找它的完全匹配
makefile_1786878:/home/user/project
我遇到的问题是,如果用户输入“mak”或“make”或“makefi”作为参数,则会错误地查找此条目
我希望它专门为此获得完全匹配,我不知道如何强制grep这样做
答案 0 :(得分:0)
尝试其中任何一个并查看它是否适合您:
grep -w "makefile"
grep "\<makefile\>"
如果有效,那么只需将你的grep更改为: grep其中一个内置$ 1参数。