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

Vá: awk FIELDWIDTHS howto?



2008/1/9, Daniel Mahoney <dan@catfolks.net>:

> I think I'm missing something here. Why are you doing the FIELDWIDTHS
> thing when you can just split on whitespace? Won't something like:
>
> aptitude search ~i | awk '{print $2}'
> give you what you want?

No.
The records for awk are like these lines, derived from
'aptitude search ~i' :

...
i   cpio                            - GNU cpio -- a program to manage archives
i A cpp                             - The GNU C preprocessor (cpp)
i A cpp-4.1                         - The GNU C preprocessor
...

So, (from the abowe example)
in the 1. record:
the 1. field is 'i', the 2. field is 'cpio', the 3. field is '-', etc.

in the 2. record:
the 1. field is 'i', the 2. field is 'A', the 3. field is 'cpp', etc.

in the 3. record:
the 1. field is 'i', the 2. field is 'A', the 3. field is 'cpp-4.1', etc.

So the command here:
aptitude search ~i | awk '{print $1" "$2" "$3" "$4}' > \
foltelepitett_debian_csomagok

give to me these:

i cpio - GNU
i A cpp -
i A cpp-4.1 -

and the command:
aptitude search ~i | awk '{print $2}' > \
foltelepitett_debian_csomagok

give to me these:

cpio
A
A

So, why don't works FIELDWIDTHS as I would to expect?
If I give to awk { FIELDWIDTHS = "4 32"} why give to me these:

cpio
A
A

with command:
aptitude search ~i | awk '{ FIELDWIDTHS = "4 32"}\
{print $2}' > foltelepitett_debian_csomagok


-- 
Regards, Paul Csanyi
http://www.freewebs.com/csanyi-pal/index.htm


Reply to: