我正在处理文件并从中过滤掉某些字段。然后,我将整个结果转换为CSV文件。但是,我过滤的最后一列是纪元时间戳(最多毫秒)。
搜索周围,我发现我可以使用jq中的strftime
函数进行转换;在整个数组中应用| strftime
时,它会将函数应用于所有值。
TZ='Asia/Kolkata' grep $id ~/hhfh.log | grep -oE '\{.+' | jq -r '[.highPrice, .lowPrice, .openPrice, .closePrice, .volumeTradedToday, .totalBuyQuantity, .totalSellQuantity, .tickTimestamp | strftime("%B %d %Y %I:%M%p %Z")]' | jq -r 'map(tostring) | join(", ")'
我可以对其进行修改,以便strftime("%B %d %Y %I:%M%p %Z")
仅适用于.tickTimestmap
值吗?如果没有,我是否必须依赖awk
?
来自hhfh.log
的记录行:
2018-03-06 03:30:04,938 DEBUG KiteTickerSourceLogic [ReadingThread] TickData: {"mode":"full","tradable":false,"instrumentToken":2997505,"lastTradedPrice":740.0,"highPrice":0.0,"lowPrice":0.0,"openPrice":731.5,"closePrice":739.9,"change":0.01351533991080183,"lastTradedQuantity":23.0,"averageTradePrice":0.0,"volumeTradedToday":12.0,"totalBuyQuantity":285.0,"totalSellQuantity":1469.0,"lastTradedTime":1520245282000,"oi":0.0,"tickTimestamp":1520307004000,"openInterestDayHigh":0.0,"openInterestDayLow":0.0,"marketDepth":{"buy":[{"quantity":1,"price":735.55,"orders":1},{"quantity":86,"price":731.5,"orders":1},{"quantity":168,"price":731.0,"orders":1},{"quantity":25,"price":730.1,"orders":1},{"quantity":0,"price":0.0,"orders":0}],"sell":[{"quantity":550,"price":743.6,"orders":1},{"quantity":550,"price":746.6,"orders":1},{"quantity":10,"price":750.0,"orders":1},{"quantity":25,"price":777.0,"orders":1},{"quantity":12,"price":-0.01,"orders":1}]}}
我目前正在制作:
January 01 1970 12:05:08AM UTC, January 01 1970 12:05:02AM UTC, January 01 1970 12:05:04AM UTC, January 01 1970 12:05:06AM UTC, January 19 1970 08:56:53AM UTC, January 01 1970 04:39:20AM UTC, January 01 1970 12:00:00AM UTC, August 31 50144 10:33:20AM UTC
应该是什么样的:
751.95, 734.1, 745.45, 742.8, 1659987, 6358, 0, <time in IST zone>
答案 0 :(得分:1)
只需使用括号:
(.tickTimestamp | strftime("%B %d %Y %I:%M%p %Z"))
如果您想要相对于TZ的时间,请使用strflocaltime
,但需要更新版本的jq而不是1.5。