[英]convert output to json in shell
input:输入:
BBAOMACBOOKAIR2?976?AMPDeviceDiscoveryAgent[976]:? - Can't handle disconnect with invalid ecid?0700-0800?8
BBAOMACBOOKAIR2?976?AMPDeviceDiscoveryAgent[976]:? - Can't handle disconnect with invalid ecid?0800-0900?40
BBAOMACBOOKAIR2?976?AMPDeviceDiscoveryAgent[976]:? - Can't handle disconnect with invalid ecid?0900-1000?18
BBAOMACBOOKAIR2?976?AMPDeviceDiscoveryAgent[976]:? - Can't handle disconnect with invalid ecid?1000-1100?14
BBAOMACBOOKAIR2?976?AMPDeviceDiscoveryAgent[976]:? - Can't handle disconnect with invalid ecid?1100-1200?2
code:代码:
input | jq -R 'split("?")|{ deviceName:.[0], ProcessId:.[1], processName:.[2], description:.[3], timeWindow:.[4], numberOfOccurrence:.[5] }
input | jq -R 'split("?")|{ deviceName:.[0], ProcessId:.[1], processName:.[2], description:.[3], timeWindow:.[4], numberOfOccurrence:.[5] }
' input | jq -R 'split("?")|{ deviceName:.[0], ProcessId:.[1], processName:.[2], description:.[3], timeWindow:.[4], numberOfOccurrence:.[5] }
'
error: I tried to solve it by searching Google results overnight, but I found nothing.错误:我试图通过在一夜之间搜索谷歌结果来解决它,但我什么也没找到。 Can you tell me where I went wrong?你能告诉我我哪里出错了吗?
jq: error: syntax error, unexpected IDENT, expecting '}' (Unix shell quoting issues?) at <top-level>, line 1:
split("?")|{ deviceName:.[0], ProcessId:.[1], processName:.[2], description:.[3] timeWindow:.[4], numberOfOccurrence:.[5] }
jq: error: May need parentheses around object key expression at <top-level>, line 1:
split("?")|{ deviceName:.[0], ProcessId:.[1], processName:.[2], description:.[3] timeWindow:.[4], numberOfOccurrence:.[5] }
There is a comma missing between the fields "description" and "timeWindow".字段“description”和“timeWindow”之间缺少逗号。 The jq
error msg reflects the typo: jq
错误 msg 反映了错字:
jq: error: syntax error, unexpected IDENT, expecting '}' (Unix shell quoting issues?) at <top-level>, line 1:
split("?")|{ deviceName:.[0], ProcessId:.[1], processName:.[2], description:.[3] timeWindow:.[4], numberOfOccurrence:.[5] }
jq: error: May need parentheses around object key expression at <top-level>, line 1:
split("?")|{ deviceName:.[0], ProcessId:.[1], processName:.[2], description:.[3] timeWindow:.[4], numberOfOccurrence:.[5] }
Your code example has the comma & works for us!您的代码示例有逗号 & 对我们有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.