您好,登錄后才能下訂單哦!
這篇文章主要介紹了Linux下jq命令怎么使用的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇Linux下jq命令怎么使用文章都會有所收獲,下面我們一起來看看吧。
[root@test-dhcp ~]# yum install jq
[root@test-dhcp ~]# jq -n {a:1}{ "a": 1 } [root@test-dhcp ~]# jq -n '{a:"test"}'{ "a": "test"}
[root@test-dhcp ~]# jq -n '{a:"test"} + {b:2}'{ "a": "test", "b": 2 } [root@test-dhcp ~]# jq -n '{a:"test"} + {b:2} + {c:"testc"}'{ "a": "test", "b": 2, "c": "testc"}
[root@test-dhcp ~]# cat test.json{"a": "test","b": 2, "c": "testc"} [root@test-dhcp ~]# cat test.json |jq .{ "a": "test", "b": 2, "c": "testc"} [root@test-dhcp ~]# cat test.json |jq 'del(.b)'{ "a": "test", "c": "testc"}
[root@test-dhcp ~]# cat test.json{"a": "test","b": 2, "c": "testc"} [root@test-dhcp ~]# cat test.json |jq '.b="testb"'{ "a": "test", "b": "testb", "c": "testc"} [root@test-dhcp ~]# cat test.json |jq '. + {d:4}'{ "a": "test", "b": 2, "c": "testc", "d": 4 } [root@test-dhcp ~]# cat test.json |jq '. + {d:4}' |jq '.d={dd:5}'{ "a": "test", "b": 2, "c": "testc", "d": { "dd": 5 } }
[root@test-dhcp ~]# cat test.json |jq .{ "a": "test", "b": 2, "c": "testc", "d": { "dd": 5 } } [root@test-dhcp ~]# cat test.json |jq '. + {d:4}' |jq '.d={dd:5}' |jq .d.dd5 [root@test-dhcp ~]# echo '{"a":1,"b":2}' |jq '[.a,.b]'[ 1, 2 ]
[root@test-dhcp ~]# echo "{}" |jq -r typeobject [root@test-dhcp ~]# echo '[0, false, [], {}, null, "hello"]' |jq 'map(type)'[ "number", "boolean", "array", "object", "null", "string"]
[root@test-dhcp ~]# echo [1,2,3] |jq .[1]2 [root@test-dhcp ~]# echo [1,2,3] |jq .[2]3
[root@test-dhcp ~]# echo [1,2,3,9] |jq '.|length'4 [root@test-dhcp ~]# echo [1,2,3] |jq '.|length'3
[root@test-dhcp ~]# echo [1,2,3] |jq '. + [4,5,6]'[ 1, 2, 3, 4, 5, 6 ]
[root@test-dhcp ~]# echo [1,2,3] | jq 'map(select(. >= 2))'[ 2, 3 ] [root@test-dhcp ~]# echo [1,2,3] | jq 'map(select(. == 2))'[ 2 ] [root@test-dhcp ~]# echo [1,2,3] | jq 'map(select(. != 2))'[ 1, 3 ] [root@test-dhcp ~]# cat test.json[ { "id": "0", "model": "Intel(R)Xeon(R)CPUE5-2620v4@2.10GHz" }, { "id": "1", "model": "Intel(R)Xeon(R)CPUE5-2620v4@2.10GHz" } ] [root@test-dhcp ~]# cat test.json |jq .[].model"Intel(R)Xeon(R)CPUE5-2620v4@2.10GHz""Intel(R)Xeon(R)CPUE5-2620v4@2.10GHz"
[root@test-dhcp ~]# echo '["a","b,c,d","e"]' |jq 'join(",")'"a,b,c,d,e"[root@test-dhcp ~]# echo '["a","b,c,d","e",1]' |jq 'join(",")'jq: error (at :1): string (",") and number (1) cannot be added [root@test-dhcp ~]# cat test.jsonliuxin,30,male jiaweiqiang,29,femal [root@test-dhcp ~]# jq -R 'split(",")|{"name":.[0],"age":.[1],"sex":.[2]}' ./test.json{ "name": "liuxin", "age": "30", "sex": "male"} { "name": "jiaweiqiang", "age": "29", "sex": "femal"} [root@test-dhcp ~]# cat test.json{ "name": "liuxin", "age": "30", "sex": "male"} { "name": "jiaweiqiang", "age": "29", "sex": "femal"} [root@test-dhcp ~]# cat test.json |jq . -c{"name":"liuxin","age":"30","sex":"male"} {"name":"jiaweiqiang","age":"29","sex":"femal"}
關于“Linux下jq命令怎么使用”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“Linux下jq命令怎么使用”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。