【发布时间】:2020-05-15 02:43:17
【问题描述】:
我正在尝试从“id”字段中提取一些特定数据,但 jq 匹配区分大小写并导致搜索出现问题(基本上不匹配,因此返回 0 个结果)。
JSON 示例:
{
"created_at": "2020-01-17T12:54:02Z",
"primary": true,
"verified": true,
"deliverable_state": "deliverable",
"undeliverable_count": 0,
"updated_at": "2020-01-17T12:54:03Z",
"url": "http://www.website.com",
"id": 376062709553,
"user_id": 374002305374,
"type": "email",
"value": "test-1234567@domain.com"
}
{
"created_at": "2019-02-07T20:49:41Z",
"primary": false,
"verified": true,
"deliverable_state": "deliverable",
"undeliverable_count": 0,
"updated_at": "2019-02-07T20:49:41Z",
"url": "http://www.website.com",
"id": 366235941554,
"user_id": 374002305374,
"type": "email",
"value": "MyEmail@domain.com"
}
当针对以下情况运行 jq 时,我得到了正确的返回:
$ jq -r '. | select(.value=="MyEmail@domain.com") .id' sample.json
366235941554
但是如果我运行不正确的情况,例如。
$ jq -r '. | select(.value=="Myemail@domain.com") .id' sample.json
...我没有得到结果。我已经阅读了一些文档,但不幸的是,我不理解用于不敏感搜索的测试/匹配/捕获标志 (https://stedolan.github.io/jq/manual/#RegularexpressionsPCRE) 或如何让它与这个“定位并给我价值”请求一起运行。
我似乎到处都搜索过,但找不到任何使用此方法的示例。
【问题讨论】: