2017-03-08 45 views
1

我有一个文件的abc.txt的内容是如何从一个文本文件

{ “storageSummary” 打印特定的词:{ “binariesSummary”:{ “binariesCount”: “703”, “binariesSize”:” 882.39 MB“,”artifactsSize“:”3.41 GB“,”优化“:”25.23%“,”itemsCount“:”4,126“,”artifactsCount“:”1,917“},”fileStoreSummary“:{”storageType“:”file - “system”,“storageDirectory”:“/ jfrog_uat_nfs/binaries”,“totalSpace”:“1.30 TB”,“usedSpace”:“1.23 GB(0.09%)”,“freeSpace”:“1.30 TB(99.91%)”}} ,“repositoriesSummaryList”:[{“repoKey”:“sbt_remote-cache”,“repoType”:“CACHE”,“foldersCount”:0,“filesCount”:0,“usedSpace”:“0字节”,“itemsCount” 0 “packageType”: “SBT”, “百分比”: “0%”},{ “repoKey”: “test7.mvlo”, “repoType”: “本地”, “foldersCount”:0 “filesCount”:1 ,“usedSpace”:“128字节”,“itemsCount”:1,“packageType”:“Maven”,“百分比”:“0%”},{“repoKey” :“scripttestkp.rplo”,“repoType”:“LOCAL”,“foldersCount”:0,“filesCount”:0,“usedSpace”:“0字节”,“itemsCount”:0,“packageType”:“RPM”, “percentage”:“0%”},{“repoKey”:“test7.grvr”,“repoType”:“VIRTUAL”,“foldersCount”:0,“filesCount”:0,“usedSpace”:“0字节”, “itemsCount”:0,“packageType”:“Gradle”,“百分比”

从该文件中如何在shell脚本中只打印“repoKey”和“usedSpace”。

+1

这是一个'json'输入?看起来像一个破'JSON'输入标题上进行验证文件,并提供完整的'json'输入。 – Inian

+0

修复输入文件后使用适当的'JSON'解析器 – Inian

+0

为什么说json是错误的,英语?看起来没问题乍一看...看起来他错过了一些剪切和粘贴也许 –

回答

-1

你需要访问:data.storageSummary.repositoriesSummaryList [I] .repoKey每个我在列表

除了在迭代有usedSpace作为重点...例如一切:data.storageSummary .fileStoreSummary.usedSpace和data.storageSummary.repositoriesSummaryList [I] .usedSpace对于每个i中的Linux机器命令行使用JQ

,该命令访问usedSpace的第一个实例是:

curl "site" | jq ".storageSummary.fileStoreSummary.usedSpace" 

输出是:

"1.23 GB (0.09%)" 

访问的值的阵列,用于repoKeys下usedSpace命令是:

curl "site" | jq ".storageSummary.repositoriesSummaryList[].usedSpace" 

输出为:

"0 bytes" 
"128 bytes" 
"0 bytes" 
"0 bytes" 

的命令访问的repoKey是值的数组:

curl "site" | jq ".storageSummary.repositoriesSummaryList[].repoKey" 

ou tput的是:

"sbt_remote-cache" 
"test7.mvlo" 
"scripttestkp.rplo" 
"test7.grvr" 

这可以通过修正提供的JSON,使其有效的,那么到https://jqplay.org/