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.