【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变量
相关推荐
Aliano21710 天前
Arrays.asList和 List<String> list = new ArrayList<>();有什么区别
数据结构·list
BillKu10 天前
Vue3 + TypeScript合并两个列表到目标列表,并且进行排序,数组合并、集合合并、列表合并、list合并
vue.js·typescript·list
77tian10 天前
Java Collections工具类:高效集合操作
java·开发语言·windows·microsoft·list
___波子 Pro Max.11 天前
python list去重
python·list
Ven%12 天前
掌握Bash脚本编写:从服务启动脚本到语法精要
linux·服务器·开发语言·chrome·bash
阿乾之铭13 天前
推送项目到GitHub
ssh·github·bash
2401_8582861113 天前
CD45.【C++ Dev】STL库的list的使用
开发语言·数据结构·c++·list
点云SLAM13 天前
PyTorch 中Tensor常用数据结构(int, list, numpy array等)互相转换和实战示例
数据结构·人工智能·pytorch·算法·list·numpy·tensor
张紫娃13 天前
bash 命令行 |
开发语言·bash
haokan_Jia15 天前
以list为输入条件,查询数据库表,java中的mapper层和mybatis层应该怎么写?
java·list·mybatis