grep命令从json中查找key的值

use*_*747 4 linux

请解释如何使用grep命令从以下json中提取一些指定的文本 -

{"result":"Customer information saved successfully with Customer id :59 and version :1","status":{"responseCode":200,"result":null,"responseMessage":"Success","responseType":"info"}}
Run Code Online (Sandbox Code Playgroud)

经过一些谷歌搜索后,通过使用带正则表达式的grep看起来是可能的.但它没有用.你能指出错误吗?

cat response.txt | grep -Po '(?<="Customer id ":)[0-9]+'
Run Code Online (Sandbox Code Playgroud)

假设:response.txt包含上面的json.

如果是,请解释.

Hac*_*lic 5

你错过了K:

cat response.txt | grep -Po 'Customer id :\K[0-9]+'
59
Run Code Online (Sandbox Code Playgroud)

截图,它的工作原理: 在此输入图像描述

  • grep 可以自己读取文件,所以`grep ... file`(猫的无用使用)。而 `\K` 是 OP 已经使用的东西的简写,积极的后视 (2认同)