假设我在python中有这个命令
response = requests.get('https://host/api/v13/clusters/cluster/services/impalaQueries', verify=false, auth=('user', pass))
其中包含如下示例数据:
"queryId" : "8f46683f7c2c8fee:6504618f00000000",
"queryState" : "FINISHED",
"rowsProduced" : null,
etc....
如何在响应变量中使用awk?例如awk-F':''/queryId/
首先:如果您的数据是JSON(在大多数情况下不是JSON),则不要使用JSON
awk不能准确地解析JSON,这就是像
jsawk
这样的专用工具被编写为替代工具的全部原因。类似地,Python附带了一个兼容的CSV解析器、多个兼容的XML解析器,以及其他工具,这些工具在处理标准格式方面要比在awk
中手工推出的任何工具做得更好。你知道吗对于您的特定用例,
requests
模块甚至会在您要求时为您调用Python的JSON解析器:第二:如果你真的想调用
awk
,使用subprocess
模块…仅正确发射:
相关问题 更多 >
编程相关推荐