Kusalananda's answer is much better than what I was thinking. One thing I had in my construct though was a condition to truncate a column if it was too long. I was able to implement this with his solution:
INPUT
component_name : TEZ_CLIENT recovery_enabled : true component_name : WEBHCAT_SERVER recovery_enabled : true component_name : YARN_CLIENT recovery_enabled : true component_name : ZKFC recovery_enabled : true component_name : ZOOKEEPER_CLIENT recovery_enabled : true component_name : ZOOKEEPER_SERVER recovery_enabled : true component_name : ZOOKEEPER_SERVER_1234567890 recovery_enabled : true
SCRIPT
# /bin/bash - # INPUT_FILE=$HOME/Documents/scripts/shell/testing/input IFS= mapfile -t STATUS_ARRAY < <(cat "$INPUT_FILE" | tr -s " ") for line in "${STATUS_ARRAY[@]}"; do COMPONENT_NAME=$(echo "$line" | awk '{print $3}') if [[ "${#COMPONENT_NAME}" -gt "16" ]]; then echo "$line" | sed "s/${COMPONENT_NAME}/${COMPONENT_NAME:0:16}../" | awk '{printf("%s %s %-20s %20s %s %s\n", $1, $2, $3, $4, $5, $6)}' else echo "$line" | awk '{printf("%s %s %-20s %20s %s %s\n", $1, $2, $3, $4, $5, $6)}' fi done
My script pulls the input from a file but you could likely also set your mapfile by echo $status | grep.. or echo $status | jq..
OUTPUT
component_name : TEZ_CLIENT recovery_enabled : true component_name : WEBHCAT_SERVER recovery_enabled : true component_name : YARN_CLIENT recovery_enabled : true component_name : ZKFC recovery_enabled : true component_name : ZOOKEEPER_CLIENT recovery_enabled : true component_name : ZOOKEEPER_SERVER recovery_enabled : true component_name : ZOOKEEPER_SERVER.. recovery_enabled : true
$statuscontent? (what givesecho "$status")json- it's even better, cause I could suggestjqsolution in that case