Re: Format Output of bash into columns

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

 



On 27-Nov-2004/08:21 -0600, Mike Vanecek <rh_list@xxxxxxxxxxxxx> 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@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