Re: Format Output of bash into columns
From: Anthony E. Greene (tony_at_greene-family.org)
Date: 11/27/04
- Previous message: Amanda Galligan: "kernel panic HP DL 380 G3"
- In reply to:(deleted message) Mike Vanecek: "Format Output of bash into columns"
- Next in thread: Mike Vanecek: "Re: Format Output of bash into columns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 26 Nov 2004 19:27:09 -0500 To: General Red Hat Linux discussion list <redhat-list@redhat.com>
On 26-Nov-2004/17:37 -0600, Mike Vanecek <rh_list@mm-vanecek.cc> 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@greene-family.org%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@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/redhat-list
- Previous message: Amanda Galligan: "kernel panic HP DL 380 G3"
- In reply to:(deleted message) Mike Vanecek: "Format Output of bash into columns"
- Next in thread: Mike Vanecek: "Re: Format Output of bash into columns"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]