我正在与一个API交互,它向我返回这样的json(实际上具有更多的属性):
{"timestamp": {"$date": 1488192218325}, "_id":103482}
{"timestamp": {"$date": 1488192216265}, "_id":302719}
{"timestamp": {"$date": 1588192216260}, "_id":302719}我想根据时间戳过滤这些json。我只想要两个日期(1488192216263和1488192216269)之间的json。我的预期输出是:
{"timestamp": {"$date": 1488192216265}, "_id":302719}我该怎么做呢?我可以使用grep或awk吗?
提前谢谢。
发布于 2017-02-27 19:44:59
awk、sed或grep都是处理文本的优秀工具。但他们并不擅长使用json。使用jq处理json文档:
jq -s --argjson low "1488192216263" --argjson up "1488192216269" \
'.[]|select(.timestamp["$date"]>=$low and .timestamp["$date"]<=$up)' file.json发布于 2017-02-27 19:45:35
下面的awk将为您提供:
awk -F '[^0-9]+' '{ if ($2 >= 1488192216263 && $2 <= 1488192216269) print $0 }' jsonfile.json发布于 2017-02-28 01:41:43
试试这个-
gawk -F'[{} ]' '($6 > 1488192216263 && $6 < 1488192216269)' timestamphttps://stackoverflow.com/questions/42484100
复制相似问题