Re: Format Output of bash into columns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 26-Nov-2004/17:37 -0600, Mike Vanecek <rh_list@xxxxxxxxxxxxx> wrote:
>I have looked through my books and googled ... Tried serveral things without
>success ...
>
>I would like to run the output of a bash command that produces 1 field per
>line output through sort and then output in 3 columns. I have looked at
>printf, fmt, column, and so on.
>
>For example,
>
>rpm -qa | sort 2>&1 |  column -c 2 
>
>rpm -qa | sort |  column -c 2
>
>Or say I have a file with a list of sorted names, for example,
>[admin@www admin]$ rpm -qa | sort -o rpm.txt
>
>Then I want to output the file with
>
>column -c 2 rpm.txt
>


#!/usr/bin/perl
#
# Format STDIN into three tab-delimited columns
#
$colnum = 1;
while ($line = <STDIN>) {
  chomp $line;
  if ($colnum < 3) {
    print "$line	";  # The whitespace is a tab character.
  } else {
    print "$line\n";
  }
}


You could get fancy using perl's formatting features, but this quick$
dirty should work for lines that are all of similar length, or for input
in an application that easily parses tab-delimited data.

Tony
-- 
Anthony E. Greene <mailto:Anthony%20E.%20Greene%20%3Ctony@xxxxxxxxxxxxxxxxx%3E>
AOL/Yahoo Messenger: TonyG05    HomePage: <http://www.greene-family.org/tony/>
OpenPGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26  C484 A42A 60DD 6C94 239D
Linux. The choice of a GNU generation <http://www.linux.org/>

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux