看板 Linux 關於我們 聯絡資訊
※ 引述《asdrt (安靜)》之銘言: : { : "id":"674579ca-8ae2-4f3c-8c2b-c8a28e106f75", : "macAddr":"04000207", : "data":"41303132352d3039302d31", : "buff":"2016-10-24T04:15:58.133Z", : "recv":"2016-10-24T04:15:57.000Z", : "extra":{"gwip":"172.16.5.15", : "gwid":"00001c497b3b8127", : "repeater":"00000000ffffffff", : "systype":4, : "rssi":-123.2, : "snr":-12.2} : } : 收到的資料並沒有分行,想說能不能寫個 shell 讓他自動分行 : 目前只是把收到的資料利用 >> 寫入到 txt 裡面 : 想說如果可以自動分行 : 這樣在資料擷取上也比較簡單 分成多行是可以,但是你後續用 >> 寫入附加到時候整個混在一起,這樣可以解析嗎? 單純分成多行很簡單,一般系統都有裝 python 這個語言的直譯器,那這樣使用: $ cat xxxx.json | python -m json.tool 即可。 像是: $ cat file.json {"current_user_url":"https://api.github.com/user","starred_url":"https://api.github.com/user/starred{/owner}{/repo}","starred_gists_url":"https://api.github.com/gists/starred","team_url":"https://api.github.com/teams","user_url":"https://api.github.com/users/{user}"} $ cat file.json | python -m json.tool { "current_user_url": "https://api.github.com/user", "starred_gists_url": "https://api.github.com/gists/starred", "starred_url": "https://api.github.com/user/starred{/owner}{/repo}", "team_url": "https://api.github.com/teams", "user_url": "https://api.github.com/users/{user}" } 都幫你排版排好了,也是多行輸出。不過你的需求都多行放成一個檔案了,解析上是另外一個層級問題了。 : 所以來請教說是否可以透過 , 來做為每一行的分行代表跟執行方式 : 另外想請問的是 : 中間"41303132352d3039302d31" 這一串是ascii code 16進位 : 有沒有工具可以將 這一串轉換回 string : 以上 : 感謝 : OS :ubuntu 10.04 LTS 可以執行 python 命令進入互動模式,輸入 "41303132352d3039302d31".decode('hex') 就可以得到: A0125-090-1 最後推薦學一點程式語言有助於問題解決,python 這個 script 很好用可以解決很多需求。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.117.155.17 ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1477309005.A.0CD.html
s58348292: 真是好人!! 10/24 20:44
holishing: 10/24 22:17