第一场比赛后的JQ停止
我有一个大文件(约500兆字节),其中数据是JSON格式。
{
"0001": [
"aaaaa",
"qqqqq"
],
"0002": [
"aaaaa"
],
"0003": [
"ccccc"
],
"0004": [
"bbbbb"
]
...
}
我需要从中提取:
aaaaa
qqqqq
目前,我进行以下jq -r'尝试。 “ 0001” | 。
如果已经找到输入,请告知我一种停止进一步侦察的方法。我知道第一个(输入|)有一个,但我不明白如何实现此命令。
I have a large file (about 500 megabytes) and the data in it is in JSON format.
{
"0001": [
"aaaaa",
"qqqqq"
],
"0002": [
"aaaaa"
],
"0003": [
"ccccc"
],
"0004": [
"bbbbb"
]
...
}
I need to extract from it:
aaaaa
qqqqq
At the moment and I do the following jq -r 'try . "0001" | .[]' ./1.txt
, it works, but the problem is that it takes a very long time because the search continues on through the whole file, instead of stopping immediately after the first match.
Please advise me a way to stop further scouting if an input has already been found. I know that there is a first(inputs | )
, but I don't understand how to implements this command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果事先知道相关密钥是JSON对象中的第一个密钥,则使用@pmf给出的使用-stream和
first/1
的解决方案适用;否则,可以对其进行适应如下:If it is known beforehand that the relevant key is the first one in the JSON object, then the solution using --stream and
first/1
as given by @pmf is applicable; otherwise, it could be adapted as follows:这适用于样本输入:
This works for the sample input: