Converting Strings to Objects with Jq
qmacro.org
qmacro.org
Command:
echo "SAP-samples/cloud-sdk-js
SAP-samples/cloud-cap-samples-java
SAP-samples/btp-setup-automator
SAP-samples/btp-ai-sustainability-bootcamp
SAP-samples/cloud-cap-samples
SAP-samples/ui5-exercises-codejam
SAP-samples/cap-sflight
SAP-samples/cloud-cf-feature-flags-sample
SAP-samples/cloud-espm-cloud-native
SAP-samples/iot-edge-samples
" | column --json --table-name SILLY_STRING --table-columns $(seq --separator=, 1 1)
Output: {
"SILLY_STRING": [
{"1": "SAP-samples/cloud-sdk-js"},
{"1": "SAP-samples/cloud-cap-samples-java"},
{"1": "SAP-samples/btp-setup-automator"},
{"1": "SAP-samples/btp-ai-sustainability-bootcamp"},
{"1": "SAP-samples/cloud-cap-samples"},
{"1": "SAP-samples/ui5-exercises-codejam"},
{"1": "SAP-samples/cap-sflight"},
{"1": "SAP-samples/cloud-cf-feature-flags-sample"},
{"1": "SAP-samples/cloud-espm-cloud-native"},
{"1": "SAP-samples/iot-edge-samples"}
]
} seq --separator=, 1 1
That is the longest way I've ever seen of writing "1" in my life. Bonus points: on Linux, it just is "1\n", versus Mac it's "1," (with no trailing newline)Is there some story to that?
TARGET_FILE=~tomcat/logs/access.log
tail \
--lines 1 ${TARGET_FILE} | \
column \
--json \
--table-name ACCESS_LOG \
--table-columns $(seq --separator=, 1 48)
And the story behind it is a bit silly but memorable. To keep things fun, our ENG team does "left field challenges" and this one was "using only core bin tools, how would you get the field numbers and field values of the tomcat access log file in json format". Its memorable because not long after the code was posted in the ENG chat, we had a PRD incident and some team members used it and found it useful.