简体   繁体   English

如何使用正则表达式或 grep 从此 json 中提取('uid')值?

[英]how to extract the ('uid') value using regex or grep from this json?

I have below API JSON response:我有以下 API JSON 响应:

https://gist.github.com/mzaboss/944d30a1c29796cbe8dbb6aa95d7e20e https://gist.github.com/mzaboss/944d30a1c29796cbe8dbb6aa95d7e20e

I'd like to extract the values of 'uid': '6904989037985481733' .我想提取'uid': '6904989037985481733'的值。

Example:例子:

6904989037985481733
6775449343043519493
6864191257082741765
6790990270277551110
6846402706555601926

etc ETC

I've tried cat ids.txt | grep 'uid'我试过cat ids.txt | grep 'uid' cat ids.txt | grep 'uid' , with failed attempted. cat ids.txt | grep 'uid' ,尝试失败。

How to make an accurate grep?如何制作准确的 grep? please

Thank you, regards.谢谢,问候。

jq is the best tool to use for json but given that the json from the link doesn't seem to be formatted correctly, you can use the following to get the UID entries: jq 是用于 json 的最佳工具,但鉴于链接中的 json 的格式似乎不正确,您可以使用以下内容获取 UID 条目:

grep -Eo "'uid': '[[:alnum:]]+'" file.json | cut -d "'" -f 4

Output the uid keys and entries with grep and then extract just the values by using cut. Output 使用 grep 的 uid 键和条目,然后使用 cut 仅提取值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM