【bash工具】jq遍历list

jq遍历list的两种方式

方法一:read -r + while循环 按行读取

bash 复制代码
$rows=$(cat file.json | jq -rc '@base64')
while IFS= read -r line; do    # IFS必须为空,才能正确按行处理
	echo $line | jq -r '.ID'   # 获取ID字段
done < file    # 读取文件内容
# done <<< "$str"  # here string方式读取bash变量

方法二:base64编码 + for循环 读取

bash 复制代码
$rows=$(cat file.json | jq -rc '@base64') # 紧凑方式输出json并编码,这样就没有空格字符
# for只能按空白字符(空格、换行符)来分割string。所以必须先用base64编码去除空格
for row in $rows; do
	echo $row | base -d | jq -r '.ID'   # base64解码,获取ID字段
done < file    # 读取文件内容
# done <<< "$str"  # here string方式读取bash变量
相关推荐
tellmewhoisi9 小时前
java8 List常用基本操作(去重,排序,转换等)
java·list
<但凡.12 小时前
Git 完全手册:从入门到团队协作实战(4)
git·bash
乌萨奇也要立志学C++17 小时前
【洛谷】单向链表、队列安排、约瑟夫问题(list相关算法题)
算法·链表·list
骁的小小站1 天前
The Missing Semester of Your CS Education 学习笔记以及一些拓展知识(六)
linux·经验分享·笔记·学习·bash
Java&Develop1 天前
Java中给List<String>去重的4种方式
java·windows·list
原来是猿2 天前
list 介绍 及 底层
数据结构·c++·list
Murphy_lx2 天前
C++中的list(2)简单复现list中的关键逻辑
开发语言·c++·list
小手cool3 天前
根据字符串数组的顺序重新排序 List顺序
java·数据结构·list
点云SLAM3 天前
C++中std::list的使用详解和综合实战代码示例
数据结构·c++·list·双向链表·c++ stl(标准模板库)·双向链表容器·中间或头尾插入/删除元素
Sirius Wu3 天前
一文说清楚Hive中常用的聚合函数[collect_list]
hive·hadoop·list