簡體   English   中英

Bash腳本將JSON變量輸出到文件

[英]Bash script output JSON variable to file

我在Ubuntu的命令行中使用twurl連接到Twitter Streaming API,並使用此處理器解析結果JSON。 我有以下命令,該命令返回從倫敦發送的推文的文本:

twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text'

這很好用,但我正在努力將結果輸出到名為london.txt的文件中。 我已經嘗試了以下方法,但是仍然沒有運氣:

twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text' > london.txt

由於我對Bash腳本還很陌生,所以我確定我誤解了'>'和'>>'的正確用法,因此,如果有人能指出正確的方向,那將非常棒!

twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text' > london.txt

它將替換粘貼在其上的每個新行。 但是,如果使用>> ,它將在文件末尾附加下一個寫操作。 因此,請嘗試以下上面的示例,我敢肯定它會起作用。

twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text' >> london.txt

您也可以使用tee命令檢查重定向旁邊正在打印的內容

twurl -t -d locations=-5.67,50.06,1.76,58.62 language=en -H stream.twitter.com /1.1/statuses/filter.json | jq '.text'| tee london.txt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM