summaryrefslogtreecommitdiff
path: root/Using JQ to construct an array and filtering empty strings.md
diff options
context:
space:
mode:
authorJasper Ras <jras@hostnet.nl>2025-04-25 16:15:25 +0200
committerJasper Ras <jras@hostnet.nl>2025-04-25 16:15:25 +0200
commitc9a730e5b363a10639309c81dab838232ee434b6 (patch)
tree56463ab88aae11ede76b21a9ac20376606d72f8f /Using JQ to construct an array and filtering empty strings.md
parentab409a3701bf59dd73dc1e0324376bdac8b6d74f (diff)
vault backup: 2025-04-25 16:15:25
Diffstat (limited to 'Using JQ to construct an array and filtering empty strings.md')
-rw-r--r--Using JQ to construct an array and filtering empty strings.md18
1 files changed, 18 insertions, 0 deletions
diff --git a/Using JQ to construct an array and filtering empty strings.md b/Using JQ to construct an array and filtering empty strings.md
new file mode 100644
index 0000000..d04c593
--- /dev/null
+++ b/Using JQ to construct an array and filtering empty strings.md
@@ -0,0 +1,18 @@
+---
+tags:
+ - jq
+ - howto
+---
+Today I learned how to use JQ to construct an array from stdin, while also filtering empty strings.
+
+In below examples the -R switch makes jq process input as raw non-json data, and the -n switch stops it from discarding the first line.
+
+```
+sudo virsh checkpoint-list --name instance-0002c4d7 | jq -Rn '[inputs | if length > 0 then . else empty end]'
+```
+^ Demonstrates use of empty
+
+```
+sudo virsh checkpoint-list --name instance-0002c4d7 | jq -Rn '[inputs | select(length > 0)]'
+```
+^ easier using select \ No newline at end of file