5

I'd normally use printf to pad each cell with enough whitespace to maintain header position over its respective column.

Ultimately I can just iterate over each line of the output and do enough cut invocations so that I printf each line, but that seems like a horribly inefficient way of going about it.

Is there a way I can turn the above output into a pretty printed format without going multiple lines or multiple calls to the same utilities?

  • 2
    input | sed -r 's/^(([^,]*.){$FIELD_COUNT}).*/' | ( IFS=, ; set -f -- $(cat) ; printf args "$@" ) – mikeserv Mar 13 '14 at 18:09
  • You could also do the above without sed at all - ( IFS=, ; set -f -- $(input) ; while [ $# -ge {$FIELD_COUNT} ] ; do { printf args $1… {$FIELD_COUNT} ; shift {$FIELD_COUNT} ; done ) – mikeserv Mar 13 '14 at 18:20
4

Someone posted the answer then immediately deleted it for some reason. They pointed me to the column command (which I just wasn't aware existed until now). Their original command wasn't 100% correct but it was still the correct response:

root@xxxxxxlp01 ~ $ spacewalk-report entitlements | cut -d, -f4,5-6 | column -t -s,
entitlement                                                                  used  total
RHN Management Entitled Servers                                              114   391
RHN Provisioning Entitled Servers                                            114   390
Virtualization Host Entitled Servers                                         0     13
Clustering technology beta                                                   0     1
Private Channel Family 1                                                     22
RHEL AS (v. 4 for x86) SDK                                                   0     12
RHEL Clustering                                                              0     1
RHEL Clustering Option Beta Debuginfo (v. 5)                                 0     1
RHEL Clustering Option Debuginfo (v. 5)                                      0     1
RHEL Desktop Beta Debuginfo (v. 5)                                           0     80
RHEL Desktop Debuginfo (v. 5)                                                0     80
RHEL Desktop FasTrack                                                        0     80
RHEL Desktop FasTrack (v. 5)                                                 0     80
RHEL Desktop Multi OS                                                        34    80
RHEL Desktop Supplementary                                                   18    80
RHEL Desktop Supplementary Beta Debuginfo (v. 5)                             0     80
RHEL Desktop Supplementary Debuginfo (v. 5)                                  0     80
RHEL Desktop Virtualization Beta Debuginfo (v. 5)                            0     80
RHEL Desktop Virtualization Debuginfo (v. 5)                                 0     80
RHEL Desktop Workstation                                                     16    80
RHEL Desktop Workstation Beta Debuginfo (v. 5)                               0     80
RHEL Desktop Workstation Debuginfo (v. 5)                                    0     80
RHEL Desktop Workstation FasTrack                                            0     80
RHEL Desktop Workstation FasTrack Debuginfo (v. 5)                           0     80
RHEL FasTrack                                                                0     59
RHEL FasTrack Debuginfo (v. 5)                                               0     59

The only difference between this answer and the one they deleted was this one keeps the cut command and adds a -s, to the end. If he posts again, I'll accept it as the answer just to be fair.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.