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

Re: Format Output of bash into columns



On 27-Nov-2004/08:21 -0600, Mike Vanecek <rh_list mm-vanecek cc> wrote:
>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?

Uh... I forgot to increment the column number.

     print "$line     ";

prints the variable and a tab, not the variable and 5 spaces. A straight
copy/paste frome the message may have resulted in spaces rather than a
tab.

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


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