我在一个文件中有以下文本
"rules": [
"/Common/Tetration_TCP_L4_ipfix",
"/Common/_sys_https_redirect"
],
"rulesReference": [
{
"link": "https://localhost/mgmt/tm/ltm/rule/~Common~Tetration_TCP_L4_ipfix?ver=12.0.0"
}想要提取当前"rules": []内部的任何内容
/Common/Tetration_TCP_L4_ipfix
/Common/_sys_https_redirect输出应该如下所示
Tetration_TCP_L4_ipfix
_sys_https_redirect但这也可以是任何东西。
发布于 2018-05-30 06:31:54
如果这是一个格式良好的JSON文件:
$ jq -r '..|select(type=="object" and has("rules")).rules|map(split("/")|.[-1])|.[]' file.json
Tetration_TCP_L4_ipfix
_sys_https_redirect这将使用jq递归地查找所有具有rules键的JSON对象。对于这些键的所有数组值,它将拆分/上的值并返回它的最后一个组件。
发布于 2018-05-30 06:34:34
使用AWK:
awk -F '[/"]' '/"rules": /,/],/{if(/"rules": |],/) next; print $(NF-1)}' file.txthttps://unix.stackexchange.com/questions/446832
复制相似问题