Closed bfinlay closed 5 years ago
The next version will support the jq options inline.
jq --raw-output "\(.one)\t\(.two)"
{"one":1,"two":"x"}
jq -r (map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv
[
{"code": "NSW", "name": "New South Wales", "level":"state", "country": "AU"},
{"code": "AB", "name": "Alberta", "level":"province", "country": "CA"},
{"code": "ABD", "name": "Aberdeenshire", "level":"council area", "country": "GB"},
{"code": "AK", "name": "Alaska", "level":"state", "country": "US"}
]
jq --raw-output (map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv
[
{"code": "NSW", "name": "New South Wales", "level":"state", "country": "AU"},
{"code": "AB", "name": "Alberta", "level":"province", "country": "CA"},
{"code": "ABD", "name": "Aberdeenshire", "level":"council area", "country": "GB"},
{"code": "AK", "name": "Alaska", "level":"state", "country": "US"}
]
jq .
[
{
"the_user": "U024HFHU5",
"the_text": "hey there"
}
]
[
{
"the_user": "U024HGJ4E",
"the_text": "right back at you"
}
]
[
{
"type": "message",
"user": "U028H5EBL",
"text": "<@U02A8N1DS>: Can I get some help with a domain registration?",
"ts": "1418301403.001783"
},
{
"type": "message",
"user": "U02A8N1DS",
"text": "Sure thing.",
"ts": "1418301427.001784"
}
]
jq --raw-input --slurp split("\\n")
foo\nbar\nbaz
jq --slurp . + [5] + [6]
[
1,
2,
3
]
jq . + [5] + [6]
[
1,
2,
3
]
jq -R .
ii kerneloops 0.12+git20140509-6ubuntu2 amd64 kernel oops tracker
ii kmod 25-1ubuntu4 amd64 tools for managing Linux kernel modules
ii libaio1:amd64 0.3.111-1 amd64 Linux kernel AIO access library - shared library
ii libdrm-amdgpu1:amd64 2.4.97-1ubuntu1 amd64 Userspace interface to amdgpu-specific kernel DRM services -- runtime
ii libdrm-amdgpu1:i386 2.4.97-1ubuntu1 i386 Userspace interface to amdgpu-specific kernel DRM services -- runtime
ii libdrm-common 2.4.97-1ubuntu1 all Userspace interface to kernel DRM services -- common files
ii libdrm-intel1:amd64 2.4.97-1ubuntu1 amd64 Userspace interface to intel-specific kernel DRM services -- runtime
ii libdrm-intel1:i386 2.4.97-1ubuntu1 i386 Userspace interface to intel-specific kernel DRM services -- runtime
ii libdrm-nouveau2:amd64 2.4.97-1ubuntu1 amd64 Userspace interface to nouveau-specific kernel DRM services -- runtime
ii libdrm-nouveau2:i386 2.4.97-1ubuntu1 i386 Userspace interface to nouveau-specific kernel DRM services -- runtime
ii libdrm-radeon1:amd64 2.4.97-1ubuntu1 amd64 Userspace interface to radeon-specific kernel DRM services -- runtime
ii libdrm-radeon1:i386 2.4.97-1ubuntu1 i386 Userspace interface to radeon-specific kernel DRM services -- runtime
ii libdrm2:amd64 2.4.97-1ubuntu1 amd64 Userspace interface to kernel DRM services -- runtime
ii libdrm2:i386 2.4.97-1ubuntu1 i386 Userspace interface to kernel DRM services -- runtime
ii libzmq5:amd64 4.3.1-3ubuntu2 amd64 lightweight messaging kernel (shared library)
ii linux-firmware 1.178.1 all Firmware for Linux kernel drivers
ii linux-generic 5.0.0.17.18 amd64 Complete Generic Linux kernel and headers
ii linux-headers-5.0.0-16 5.0.0-16.17 all Header files related to Linux kernel version 5.0.0
ii linux-headers-5.0.0-16-generic 5.0.0-16.17 amd64 Linux kernel headers for version 5.0.0 on 64 bit x86 SMP
ii linux-headers-5.0.0-17 5.0.0-17.18 all Header files related to Linux kernel version 5.0.0
ii linux-headers-5.0.0-17-generic 5.0.0-17.18 amd64 Linux kernel headers for version 5.0.0 on 64 bit x86 SMP
ii linux-headers-generic 5.0.0.17.18 amd64 Generic Linux kernel headers
rc linux-image-4.18.0-13-generic 4.18.0-13.14 amd64 Signed kernel image generic
rc linux-image-4.18.0-14-generic 4.18.0-14.15 amd64 Signed kernel image generic
rc linux-image-4.18.0-15-generic 4.18.0-15.16 amd64 Signed kernel image generic
rc linux-image-4.18.0-17-generic 4.18.0-17.18 amd64 Signed kernel image generic
rc linux-image-5.0.0-13-generic 5.0.0-13.14 amd64 Signed kernel image generic
rc linux-image-5.0.0-15-generic 5.0.0-15.16 amd64 Signed kernel image generic
ii linux-image-5.0.0-16-generic 5.0.0-16.17 amd64 Signed kernel image generic
ii linux-image-5.0.0-17-generic 5.0.0-17.18 amd64 Signed kernel image generic
ii linux-image-generic 5.0.0.17.18 amd64 Generic Linux kernel image
rc linux-modules-4.18.0-10-generic 4.18.0-10.11 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-4.18.0-13-generic 4.18.0-13.14 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-4.18.0-14-generic 4.18.0-14.15 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-4.18.0-15-generic 4.18.0-15.16 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-4.18.0-17-generic 4.18.0-17.18 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-5.0.0-13-generic 5.0.0-13.14 amd64 Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
rc linux-modules-5.0.0-15-generic 5.0.0-15.16 amd64 Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
ii linux-modules-5.0.0-16-generic 5.0.0-16.17 amd64 Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
ii linux-modules-5.0.0-17-generic 5.0.0-17.18 amd64 Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
rc linux-modules-extra-4.18.0-13-generic 4.18.0-13.14 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-extra-4.18.0-14-generic 4.18.0-14.15 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-extra-4.18.0-15-generic 4.18.0-15.16 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-extra-4.18.0-17-generic 4.18.0-17.18 amd64 Linux kernel extra modules for version 4.18.0 on 64 bit x86 SMP
rc linux-modules-extra-5.0.0-13-generic 5.0.0-13.14 amd64 Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
rc linux-modules-extra-5.0.0-15-generic 5.0.0-15.16 amd64 Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
ii linux-modules-extra-5.0.0-16-generic 5.0.0-16.17 amd64 Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
ii linux-modules-extra-5.0.0-17-generic 5.0.0-17.18 amd64 Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
ii linux-signed-generic 5.0.0.17.18 amd64 Complete Signed Generic Linux kernel and headers (dummy transitional package)
ii nvidia-kernel-common-390 390.116-0ubuntu1 amd64 Shared files used with the kernel module
ii nvidia-kernel-source-390 390.116-0ubuntu1 amd64 NVIDIA kernel source package
ii rsyslog 8.32.0-1ubuntu7 amd64 reliable system and kernel logging daemon
# use the output of the previous command
jq -s .
Untitled-1
very useful plugin, thanks.
Is there a way to pass command parameters like -r / --raw-output? https://stedolan.github.io/jq/manual/#Invokingjq
example use-case: removing value double quotes before piping to @csv