Printing multi-line variable output into a single column











up vote
0
down vote

favorite












I have the following script in works:



#!/bin/bash
IFS=$(echo -en "nb")

echo -e "----------------------------------------------------------------------------------------------"
echo -e "| Job Name | Enabled | Client Names | Retention | Schedule | Type |"
echo -e "----------------------------------------------------------------------------------------------"

vcenter_name=$(cat /usr/local/vdr/etc/vcenterinfo.cfg | grep vcenter-hostname | cut -d '=' -f 2)
# To extract job names:
job_name=$(mccli group show --recursive=true | grep -i "/$vcenter_name/VirtualMachines" | awk -F/. '{print $(NF-2)}')

for i in $job_name
do
enabled=$(mccli group show --name=/$vcenter_name/VirtualMachines/$i | grep Enabled | awk '{print $NF}')
client_name=$(mccli group show-members --name=/vcenter-prod.happycow.local/VirtualMachines/$i | awk '{print $3}' | tail -n +4 | awk -F/ '{print $NF}')
printf "| %-27s | %7s | %7s | %10s | %7s | %12s |n" "$i" "$enabled" "$client_name"
done


The script runs great but needs some formatting.
The output I get now is:



----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B
VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
ESXi-6.5
ESXi6GA | | | |


I would like to see it as:



----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B | | | |
| VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
| ESXi6.5
| ESXi6GA | | | |


Ignore the | alignment. I can take care of that one.
So basically, I would like to have the multi value / multi line output of job_name variable under a single column.










share|improve this question
























  • 1. a report script like this would be better written entirely in awk or perl (or anything else but sh or bash) - trying to do it in bash will result in an unreadable mess. BTW, perl has great built-in report writing capabilities (see man perlform). 2. we need to sample input, not just the desired output. 3. some basic bash/shell tips: use IFS=$'nb', not IFS=$(echo "nb"); there's no need to pipe cat into grep or grep into awk - both are capable of reading files without cat's help. e.g. vcenter_name=$(awk -F= '{print $2}' /usr/local/vdr/etc/vcenterinfo.cfg)
    – cas
    Aug 2 '17 at 3:56












  • Thanks. Still learning things in bash, thanks for the input on better scripting. :)
    – suhas savkoor
    Aug 2 '17 at 18:21

















up vote
0
down vote

favorite












I have the following script in works:



#!/bin/bash
IFS=$(echo -en "nb")

echo -e "----------------------------------------------------------------------------------------------"
echo -e "| Job Name | Enabled | Client Names | Retention | Schedule | Type |"
echo -e "----------------------------------------------------------------------------------------------"

vcenter_name=$(cat /usr/local/vdr/etc/vcenterinfo.cfg | grep vcenter-hostname | cut -d '=' -f 2)
# To extract job names:
job_name=$(mccli group show --recursive=true | grep -i "/$vcenter_name/VirtualMachines" | awk -F/. '{print $(NF-2)}')

for i in $job_name
do
enabled=$(mccli group show --name=/$vcenter_name/VirtualMachines/$i | grep Enabled | awk '{print $NF}')
client_name=$(mccli group show-members --name=/vcenter-prod.happycow.local/VirtualMachines/$i | awk '{print $3}' | tail -n +4 | awk -F/ '{print $NF}')
printf "| %-27s | %7s | %7s | %10s | %7s | %12s |n" "$i" "$enabled" "$client_name"
done


The script runs great but needs some formatting.
The output I get now is:



----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B
VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
ESXi-6.5
ESXi6GA | | | |


I would like to see it as:



----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B | | | |
| VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
| ESXi6.5
| ESXi6GA | | | |


Ignore the | alignment. I can take care of that one.
So basically, I would like to have the multi value / multi line output of job_name variable under a single column.










share|improve this question
























  • 1. a report script like this would be better written entirely in awk or perl (or anything else but sh or bash) - trying to do it in bash will result in an unreadable mess. BTW, perl has great built-in report writing capabilities (see man perlform). 2. we need to sample input, not just the desired output. 3. some basic bash/shell tips: use IFS=$'nb', not IFS=$(echo "nb"); there's no need to pipe cat into grep or grep into awk - both are capable of reading files without cat's help. e.g. vcenter_name=$(awk -F= '{print $2}' /usr/local/vdr/etc/vcenterinfo.cfg)
    – cas
    Aug 2 '17 at 3:56












  • Thanks. Still learning things in bash, thanks for the input on better scripting. :)
    – suhas savkoor
    Aug 2 '17 at 18:21















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have the following script in works:



#!/bin/bash
IFS=$(echo -en "nb")

echo -e "----------------------------------------------------------------------------------------------"
echo -e "| Job Name | Enabled | Client Names | Retention | Schedule | Type |"
echo -e "----------------------------------------------------------------------------------------------"

vcenter_name=$(cat /usr/local/vdr/etc/vcenterinfo.cfg | grep vcenter-hostname | cut -d '=' -f 2)
# To extract job names:
job_name=$(mccli group show --recursive=true | grep -i "/$vcenter_name/VirtualMachines" | awk -F/. '{print $(NF-2)}')

for i in $job_name
do
enabled=$(mccli group show --name=/$vcenter_name/VirtualMachines/$i | grep Enabled | awk '{print $NF}')
client_name=$(mccli group show-members --name=/vcenter-prod.happycow.local/VirtualMachines/$i | awk '{print $3}' | tail -n +4 | awk -F/ '{print $NF}')
printf "| %-27s | %7s | %7s | %10s | %7s | %12s |n" "$i" "$enabled" "$client_name"
done


The script runs great but needs some formatting.
The output I get now is:



----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B
VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
ESXi-6.5
ESXi6GA | | | |


I would like to see it as:



----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B | | | |
| VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
| ESXi6.5
| ESXi6GA | | | |


Ignore the | alignment. I can take care of that one.
So basically, I would like to have the multi value / multi line output of job_name variable under a single column.










share|improve this question















I have the following script in works:



#!/bin/bash
IFS=$(echo -en "nb")

echo -e "----------------------------------------------------------------------------------------------"
echo -e "| Job Name | Enabled | Client Names | Retention | Schedule | Type |"
echo -e "----------------------------------------------------------------------------------------------"

vcenter_name=$(cat /usr/local/vdr/etc/vcenterinfo.cfg | grep vcenter-hostname | cut -d '=' -f 2)
# To extract job names:
job_name=$(mccli group show --recursive=true | grep -i "/$vcenter_name/VirtualMachines" | awk -F/. '{print $(NF-2)}')

for i in $job_name
do
enabled=$(mccli group show --name=/$vcenter_name/VirtualMachines/$i | grep Enabled | awk '{print $NF}')
client_name=$(mccli group show-members --name=/vcenter-prod.happycow.local/VirtualMachines/$i | awk '{print $3}' | tail -n +4 | awk -F/ '{print $NF}')
printf "| %-27s | %7s | %7s | %10s | %7s | %12s |n" "$i" "$enabled" "$client_name"
done


The script runs great but needs some formatting.
The output I get now is:



----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B
VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
ESXi-6.5
ESXi6GA | | | |


I would like to see it as:



----------------------------------------------------------------------------------------------
| Job Name | Enabled | Client Names | Retention | Schedule | Type |
----------------------------------------------------------------------------------------------
| Backup With Space | true | Space | | | |
| Disk-Level | true | | | | |
| Linux-VM | true | | | | |
| Partial | true | | | | |
| Prod-Backup | false | VM-B | | | |
| VM-D | | | |
| Same-Host | true | | | | |
| Temp | true | esxi02
| ESXi6.5
| ESXi6GA | | | |


Ignore the | alignment. I can take care of that one.
So basically, I would like to have the multi value / multi line output of job_name variable under a single column.







bash shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Rui F Ribeiro

38.2k1475125




38.2k1475125










asked Aug 1 '17 at 21:04









suhas savkoor

104116




104116












  • 1. a report script like this would be better written entirely in awk or perl (or anything else but sh or bash) - trying to do it in bash will result in an unreadable mess. BTW, perl has great built-in report writing capabilities (see man perlform). 2. we need to sample input, not just the desired output. 3. some basic bash/shell tips: use IFS=$'nb', not IFS=$(echo "nb"); there's no need to pipe cat into grep or grep into awk - both are capable of reading files without cat's help. e.g. vcenter_name=$(awk -F= '{print $2}' /usr/local/vdr/etc/vcenterinfo.cfg)
    – cas
    Aug 2 '17 at 3:56












  • Thanks. Still learning things in bash, thanks for the input on better scripting. :)
    – suhas savkoor
    Aug 2 '17 at 18:21




















  • 1. a report script like this would be better written entirely in awk or perl (or anything else but sh or bash) - trying to do it in bash will result in an unreadable mess. BTW, perl has great built-in report writing capabilities (see man perlform). 2. we need to sample input, not just the desired output. 3. some basic bash/shell tips: use IFS=$'nb', not IFS=$(echo "nb"); there's no need to pipe cat into grep or grep into awk - both are capable of reading files without cat's help. e.g. vcenter_name=$(awk -F= '{print $2}' /usr/local/vdr/etc/vcenterinfo.cfg)
    – cas
    Aug 2 '17 at 3:56












  • Thanks. Still learning things in bash, thanks for the input on better scripting. :)
    – suhas savkoor
    Aug 2 '17 at 18:21


















1. a report script like this would be better written entirely in awk or perl (or anything else but sh or bash) - trying to do it in bash will result in an unreadable mess. BTW, perl has great built-in report writing capabilities (see man perlform). 2. we need to sample input, not just the desired output. 3. some basic bash/shell tips: use IFS=$'nb', not IFS=$(echo "nb"); there's no need to pipe cat into grep or grep into awk - both are capable of reading files without cat's help. e.g. vcenter_name=$(awk -F= '{print $2}' /usr/local/vdr/etc/vcenterinfo.cfg)
– cas
Aug 2 '17 at 3:56






1. a report script like this would be better written entirely in awk or perl (or anything else but sh or bash) - trying to do it in bash will result in an unreadable mess. BTW, perl has great built-in report writing capabilities (see man perlform). 2. we need to sample input, not just the desired output. 3. some basic bash/shell tips: use IFS=$'nb', not IFS=$(echo "nb"); there's no need to pipe cat into grep or grep into awk - both are capable of reading files without cat's help. e.g. vcenter_name=$(awk -F= '{print $2}' /usr/local/vdr/etc/vcenterinfo.cfg)
– cas
Aug 2 '17 at 3:56














Thanks. Still learning things in bash, thanks for the input on better scripting. :)
– suhas savkoor
Aug 2 '17 at 18:21






Thanks. Still learning things in bash, thanks for the input on better scripting. :)
– suhas savkoor
Aug 2 '17 at 18:21












1 Answer
1






active

oldest

votes

















up vote
1
down vote













One approach is the following where we make use of nroff and tbl. We first generate the code for the tbl preprocessor based on the data.



Since I don't have access to your utilities so I have modeled your program behavior on the following, which you'd have to then incorporate in your case:



#!/bin/bash

NL=$'n'
TAB=$'t'

header=( "Job Name" "Enabled" "Client Names" "Retention" "Schedule" "Type" )

job_name=( "Backup With Space" "Disk-Level" "Linux-VM" "Partial" "Prod-Backup" "Same-Host" "Temp" )
enabled=( true true true true false true true )
client=( Space "" "" "" "VM_B${NL}VM_D" "" "esxio2${NL}ESXi-6.5${NL}ESXi6GA" )

{
echo .TS
echo allbox,center,tab($'t');
echo l r l l l l l.
echo "$(IFS=$'t'; echo "${header[*]}")"
for (( i=0; i<${#enabled[@]}; i++ ))
do
var=${client[$i]//$NL/$NL$TAB$TAB}
printf '%st%st%stttn' "${job_name[$i]}" "${enabled[$i]}" "${var}"
done
echo .TE
} | tbl - | nroff -Tascii -ms | grep '.'




Results:



+------------------+---------+--------------+-----------+----------+------+
|Job Name | Enabled | Client Names | Retention | Schedule | Type |
+------------------+---------+--------------+-----------+----------+------+
|Backup With Space | true | Space | | | |
+------------------+---------+--------------+-----------+----------+------+
|Disk-Level | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Linux-VM | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Partial | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Prod-Backup | false | VM_B | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | VM_D | | | |
+------------------+---------+--------------+-----------+----------+------+
|Same-Host | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Temp | true | esxio2 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi-6.5 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi6GA | | | |
+------------------+---------+--------------+-----------+----------+------+





share|improve this answer





















  • Thanks for all the suggestions. I was able to get this done by adding a loop for the client list and add "" to ignore additional values. Thanks.
    – suhas savkoor
    Aug 2 '17 at 18:20










  • +1. nice, i was thinking of doing something similar with markdown but got distracted by real life.
    – cas
    Aug 2 '17 at 18:31











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f383282%2fprinting-multi-line-variable-output-into-a-single-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













One approach is the following where we make use of nroff and tbl. We first generate the code for the tbl preprocessor based on the data.



Since I don't have access to your utilities so I have modeled your program behavior on the following, which you'd have to then incorporate in your case:



#!/bin/bash

NL=$'n'
TAB=$'t'

header=( "Job Name" "Enabled" "Client Names" "Retention" "Schedule" "Type" )

job_name=( "Backup With Space" "Disk-Level" "Linux-VM" "Partial" "Prod-Backup" "Same-Host" "Temp" )
enabled=( true true true true false true true )
client=( Space "" "" "" "VM_B${NL}VM_D" "" "esxio2${NL}ESXi-6.5${NL}ESXi6GA" )

{
echo .TS
echo allbox,center,tab($'t');
echo l r l l l l l.
echo "$(IFS=$'t'; echo "${header[*]}")"
for (( i=0; i<${#enabled[@]}; i++ ))
do
var=${client[$i]//$NL/$NL$TAB$TAB}
printf '%st%st%stttn' "${job_name[$i]}" "${enabled[$i]}" "${var}"
done
echo .TE
} | tbl - | nroff -Tascii -ms | grep '.'




Results:



+------------------+---------+--------------+-----------+----------+------+
|Job Name | Enabled | Client Names | Retention | Schedule | Type |
+------------------+---------+--------------+-----------+----------+------+
|Backup With Space | true | Space | | | |
+------------------+---------+--------------+-----------+----------+------+
|Disk-Level | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Linux-VM | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Partial | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Prod-Backup | false | VM_B | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | VM_D | | | |
+------------------+---------+--------------+-----------+----------+------+
|Same-Host | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Temp | true | esxio2 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi-6.5 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi6GA | | | |
+------------------+---------+--------------+-----------+----------+------+





share|improve this answer





















  • Thanks for all the suggestions. I was able to get this done by adding a loop for the client list and add "" to ignore additional values. Thanks.
    – suhas savkoor
    Aug 2 '17 at 18:20










  • +1. nice, i was thinking of doing something similar with markdown but got distracted by real life.
    – cas
    Aug 2 '17 at 18:31















up vote
1
down vote













One approach is the following where we make use of nroff and tbl. We first generate the code for the tbl preprocessor based on the data.



Since I don't have access to your utilities so I have modeled your program behavior on the following, which you'd have to then incorporate in your case:



#!/bin/bash

NL=$'n'
TAB=$'t'

header=( "Job Name" "Enabled" "Client Names" "Retention" "Schedule" "Type" )

job_name=( "Backup With Space" "Disk-Level" "Linux-VM" "Partial" "Prod-Backup" "Same-Host" "Temp" )
enabled=( true true true true false true true )
client=( Space "" "" "" "VM_B${NL}VM_D" "" "esxio2${NL}ESXi-6.5${NL}ESXi6GA" )

{
echo .TS
echo allbox,center,tab($'t');
echo l r l l l l l.
echo "$(IFS=$'t'; echo "${header[*]}")"
for (( i=0; i<${#enabled[@]}; i++ ))
do
var=${client[$i]//$NL/$NL$TAB$TAB}
printf '%st%st%stttn' "${job_name[$i]}" "${enabled[$i]}" "${var}"
done
echo .TE
} | tbl - | nroff -Tascii -ms | grep '.'




Results:



+------------------+---------+--------------+-----------+----------+------+
|Job Name | Enabled | Client Names | Retention | Schedule | Type |
+------------------+---------+--------------+-----------+----------+------+
|Backup With Space | true | Space | | | |
+------------------+---------+--------------+-----------+----------+------+
|Disk-Level | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Linux-VM | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Partial | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Prod-Backup | false | VM_B | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | VM_D | | | |
+------------------+---------+--------------+-----------+----------+------+
|Same-Host | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Temp | true | esxio2 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi-6.5 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi6GA | | | |
+------------------+---------+--------------+-----------+----------+------+





share|improve this answer





















  • Thanks for all the suggestions. I was able to get this done by adding a loop for the client list and add "" to ignore additional values. Thanks.
    – suhas savkoor
    Aug 2 '17 at 18:20










  • +1. nice, i was thinking of doing something similar with markdown but got distracted by real life.
    – cas
    Aug 2 '17 at 18:31













up vote
1
down vote










up vote
1
down vote









One approach is the following where we make use of nroff and tbl. We first generate the code for the tbl preprocessor based on the data.



Since I don't have access to your utilities so I have modeled your program behavior on the following, which you'd have to then incorporate in your case:



#!/bin/bash

NL=$'n'
TAB=$'t'

header=( "Job Name" "Enabled" "Client Names" "Retention" "Schedule" "Type" )

job_name=( "Backup With Space" "Disk-Level" "Linux-VM" "Partial" "Prod-Backup" "Same-Host" "Temp" )
enabled=( true true true true false true true )
client=( Space "" "" "" "VM_B${NL}VM_D" "" "esxio2${NL}ESXi-6.5${NL}ESXi6GA" )

{
echo .TS
echo allbox,center,tab($'t');
echo l r l l l l l.
echo "$(IFS=$'t'; echo "${header[*]}")"
for (( i=0; i<${#enabled[@]}; i++ ))
do
var=${client[$i]//$NL/$NL$TAB$TAB}
printf '%st%st%stttn' "${job_name[$i]}" "${enabled[$i]}" "${var}"
done
echo .TE
} | tbl - | nroff -Tascii -ms | grep '.'




Results:



+------------------+---------+--------------+-----------+----------+------+
|Job Name | Enabled | Client Names | Retention | Schedule | Type |
+------------------+---------+--------------+-----------+----------+------+
|Backup With Space | true | Space | | | |
+------------------+---------+--------------+-----------+----------+------+
|Disk-Level | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Linux-VM | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Partial | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Prod-Backup | false | VM_B | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | VM_D | | | |
+------------------+---------+--------------+-----------+----------+------+
|Same-Host | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Temp | true | esxio2 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi-6.5 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi6GA | | | |
+------------------+---------+--------------+-----------+----------+------+





share|improve this answer












One approach is the following where we make use of nroff and tbl. We first generate the code for the tbl preprocessor based on the data.



Since I don't have access to your utilities so I have modeled your program behavior on the following, which you'd have to then incorporate in your case:



#!/bin/bash

NL=$'n'
TAB=$'t'

header=( "Job Name" "Enabled" "Client Names" "Retention" "Schedule" "Type" )

job_name=( "Backup With Space" "Disk-Level" "Linux-VM" "Partial" "Prod-Backup" "Same-Host" "Temp" )
enabled=( true true true true false true true )
client=( Space "" "" "" "VM_B${NL}VM_D" "" "esxio2${NL}ESXi-6.5${NL}ESXi6GA" )

{
echo .TS
echo allbox,center,tab($'t');
echo l r l l l l l.
echo "$(IFS=$'t'; echo "${header[*]}")"
for (( i=0; i<${#enabled[@]}; i++ ))
do
var=${client[$i]//$NL/$NL$TAB$TAB}
printf '%st%st%stttn' "${job_name[$i]}" "${enabled[$i]}" "${var}"
done
echo .TE
} | tbl - | nroff -Tascii -ms | grep '.'




Results:



+------------------+---------+--------------+-----------+----------+------+
|Job Name | Enabled | Client Names | Retention | Schedule | Type |
+------------------+---------+--------------+-----------+----------+------+
|Backup With Space | true | Space | | | |
+------------------+---------+--------------+-----------+----------+------+
|Disk-Level | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Linux-VM | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Partial | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Prod-Backup | false | VM_B | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | VM_D | | | |
+------------------+---------+--------------+-----------+----------+------+
|Same-Host | true | | | | |
+------------------+---------+--------------+-----------+----------+------+
|Temp | true | esxio2 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi-6.5 | | | |
+------------------+---------+--------------+-----------+----------+------+
| | | ESXi6GA | | | |
+------------------+---------+--------------+-----------+----------+------+






share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 2 '17 at 6:25







user218374



















  • Thanks for all the suggestions. I was able to get this done by adding a loop for the client list and add "" to ignore additional values. Thanks.
    – suhas savkoor
    Aug 2 '17 at 18:20










  • +1. nice, i was thinking of doing something similar with markdown but got distracted by real life.
    – cas
    Aug 2 '17 at 18:31


















  • Thanks for all the suggestions. I was able to get this done by adding a loop for the client list and add "" to ignore additional values. Thanks.
    – suhas savkoor
    Aug 2 '17 at 18:20










  • +1. nice, i was thinking of doing something similar with markdown but got distracted by real life.
    – cas
    Aug 2 '17 at 18:31
















Thanks for all the suggestions. I was able to get this done by adding a loop for the client list and add "" to ignore additional values. Thanks.
– suhas savkoor
Aug 2 '17 at 18:20




Thanks for all the suggestions. I was able to get this done by adding a loop for the client list and add "" to ignore additional values. Thanks.
– suhas savkoor
Aug 2 '17 at 18:20












+1. nice, i was thinking of doing something similar with markdown but got distracted by real life.
– cas
Aug 2 '17 at 18:31




+1. nice, i was thinking of doing something similar with markdown but got distracted by real life.
– cas
Aug 2 '17 at 18:31


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f383282%2fprinting-multi-line-variable-output-into-a-single-column%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt