arrays - Filtering JSON list in shell using jq
问题描述
Input :
{ "names" : ["name1","name2","name3","pat_name4"] }
Needed output :
{ "names" : ["name1","name2","name3"] }
Currently what i have by running command, to filter out all names starting with pat_
cat file | jq .names | grep -Ev '^(pat_)'
is this
["name1","name2","name3"]
Was wondering if there is some alteration to the jq command that could be done to get in the format needed.
解决方案
根据您的输入,调用:
$ jq -c '.names |= map(select(test("^pat_")|not))'
产生:
{"names":["name1","name2","name3"]}
推荐阅读
- java - “发生了错误。查看日志文件..” 在 Ubuntu 18.04.4 LTS 上安装 eclipse 的问题
- c# - 如何更改 ListView 中部分文本的颜色?
- python - Python - 如何将值添加到第一列并附加
- webpack - 由于 ES6 的扩展语法,Webpack 和 Babel 没有在 node_modules 中转换破坏 IE 11 和 Edge 的依赖项
- javascript - php标头更改后Javascript动画不起作用
- python - 如何将子进程中的密码传递给 MySQL
- c++ - 如何提升 cppcheck 中的特定样式错误
- excel - 根据另一列上的 IF 语句在 Msgbox 中显示单元格值 - Excel VBA
- reactjs - 如何通过 axios 在 Reactjs 中使用多个参数发出 post 请求
- swift - 我可以制作一个 Swift 枚举泛型,以便我可以使用它的案例来推断泛型类的类型吗?