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

Re: Vá: awk FIELDWIDTHS howto?



On  9 Jan, Sergio Cuéllar Valdés wrote:

> 2008/1/9, Paul Csanyi <csanyipal@gmail.com>:
>> 2008/1/9, Sergio Cuéllar Valdés <herrsergio@gmail.com>:
>> > 2008/1/9, Paul Csanyi <csanyipal@gmail.com>:
>>
>> > > I try to use awk to print second field from a text file
>> > > but awk prints a part of 1. field as a 2. field. Why?
>> > >
>> > > aptitude search ~i | awk '{ NF = "2" } { FIELDWIDTHS = " 4 32 " }
>> > > {print $2}' > foltelepitett_debian_csomagok
>> > >
>> > > less foltelepitett_debian_csomagok
>> > >
>> > > ..
>> > > bsdmainutils
>> > > bsdutils
>> > > busybox
>> > > A
>> > > ca-certificates
>> > > checksecurity
>>
>> A record is like these:
>>
>> i busybox - Tiny utilities for small and embedded syst
>> i A bzip2 - high-quality block-sorting file compressor
>>     |
>> 1234123456789etc.
>> 1.  |2.
>>
>> I try to get only the package name from the 2. field.
>>
>> FIELDWIDTHS = " 4 32 "
>>
>> The given width for 1. field (4) should be right, but isn't.
>> Awk give me the letter "A" as a 2. field. Why?
>>

It seem that gawk is behaving weirdly when using FIELDWIDTHS.  It splits
the input line into one less field that the number given.  

Is this a bug that should be reported?  Try this:

$ aptitude search ~i | awk 'BEGIN {FIELDWIDTHS="4 32 1"} {print $2}' | head
acpi
adduser
alsa-base
alsa-utils
amarok
amarok-engines
amarok-xine
apt
apt-build
apt-doc

-Chris




------------------------------------------------------------------------
|   Christopher Judd, Ph. D.                                           |
|   Research Scientist III                                             |
|   NYS Dept. of Health                           judd@wadsworth.org   | 
|   Wadsworth Center - ESP                                             |
|   P. O. Box 509                                    518 486-7829      |
|   Albany, NY 12201-0509                                              |
------------------------------------------------------------------------


IMPORTANT NOTICE: This e-mail and any attachments may contain
confidential or sensitive information which is, or may be, legally
privileged or otherwise protected by law from further disclosure.  It
is intended only for the addressee.  If you received this in error or
from someone who was not authorized to send it to you, please do not
distribute, copy or use it or any attachments.  Please notify the
sender immediately by reply e-mail and delete this from your
system. Thank you for your cooperation.



Reply to: