我正在尝试转换下面的字符串是存储在一个txt文件到json格式的字符串
High Severity Results: 0
Medium Severity Results: 1
Low Severity Results: 2
Information Severity Results: 0
Scan Results Location: Https://www.checkmarx.abc.com/cxwebclient/viewermain.aspx?scanid=12345&projectid=1234
到json格式以下
{
"High Severity Results" : "0",
"Medium Severity Results" : "1",
"Low Severity Results" : "2",
"Information Severity Results" : "0",
"Scan Results Location" : "Https://www.checkmarx.abc.com/cxwebclient/viewermain.aspx?scanid=12345&projectid=1234",
}
我尝试了以下命令。
file="Checkmarx_Json_Data.txt"
checkmarxDataNew="$(cat Checkmarx_Json_Data.txt)"
while IFS= read -r line || [[ -n "$line" ]]; do
for val in $line
do
echo "\"${val//:/\":\"}\"" >> ACM_BQ_JSON_Response.json
done
done < "$file"
但上述脚本正在生成以下格式的响应
"checkmarx" : {
"High"
"Severity"
"Results":""
"0"
"Medium"
"Severity"
"Results":""
"1"
"Low"
"Severity"
"Results":""
"2"
"Information"
"Severity"
"Results":""
"0"
"Scan"
"Results"
"Location":""
"Https":"//www.checkmarx.ford.com/cxwebclient/viewermain.aspx?scanid=2500093&projectid=28069"
}
当我尝试用一个像color:red这样的单字符串时,效果很好。
有人能帮我解决这个问题吗?
3条答案
按热度按时间fruv7luv1#
下面是使用
jq
可以实现的方法:输出:
vc9ivgsu2#
使用
sed
exdqitrt3#
如果
ed
可用/可接受,则如下所示:script.ed
(根据自己的内心内容命名)现在运行:
要使用编辑的输出创建新文件,