Re: Format Output of bash into columns

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

 



On Fri, 26 Nov 2004 19:27:09 -0500, Anthony E. Greene wrote

> #!/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.

Um ... what am I missing here? Isn't $colnum always < 3? Also, what do you 
mean about the whitespace is the tab character?

I get 

[admin@www admin]$ ./parse.sh < rpm.txt
4Suite-0.11.1-13     a2ps-4.13b-28     aalib-1.4.0-0.fdr.0.8.rc5.rh90     acl-
2.2.3-1     acroread-5.08-2     acroread-plugin-5.08-2     alchemist-1.0.26-
1     alsa-lib-0.9.4-fr1     amavisd-new-20030616-p8     anacron-2.3-25     
apmd-3.0.2-18     arc-5.21j-0.fdr.1.rh90     arts-1.1-7     ash-0.3.8-8     
asp2php-0.76.2-5     asp2php-gtk-0.76.2-5    ...

where

$ less rpm.txt
4Suite-0.11.1-13
a2ps-4.13b-28
aalib-1.4.0-0.fdr.0.8.rc5.rh90
acl-2.2.3-1
acroread-5.08-2
acroread-plugin-5.08-2
alchemist-1.0.26-1
alsa-lib-0.9.4-fr1
amavisd-new-20030616-p8
anacron-2.3-25
...

What am I doing wrong?

-- 
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