sample.json
{
"secondJudgeRuleId": "202002171519149514,202002171521006374,202002171523189362",
"ruleCategory": 1,
"optUser": "admin",
"requestFilePath": "/home1/test",
"ruleStatus": 1,
"algolId": "1101",
"providerId": 1,
"ruleDesc": "规则A",
"ruleType": "1,2,31,32,33,5,6,7,8,9",
"ruleName": "识别规则A",
"resultFilePath": "/home/cpap/ill_web_ident/caijdyssb",
"ruleId": "202002171456103327"
}
shell脚本处理
#!/bin/bash
function getJsonValueByPython() {
if which python; then
local key="$1"
python -c "import json,sys; print(json.load(sys.stdin).get('$key'));"
return 0
else
return 1
fi
}
key_input=$1
ruleName=`cat /root/ldd/parsing_json/test_data/sample.json | getJsonValueByPython ${key_input} | awk -F '/root/anaconda3/bin/python' '{print $1}'`
echo ${ruleName}