FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 01-09-2008, 06:48 PM
"Paul Csanyi"
 
Default Vá: awk FIELDWIDTHS howto?

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?

> something like this: aptitude search ~i | cut -d" " -f2
> does this help you ?

No.

--
Regards, Paul Csanyi
http://www.freewebs.com/csanyi-pal/index.htm
 
Old 01-09-2008, 06:53 PM
"Sergio Cuéllar Valdés"
 
Default Vá: awk FIELDWIDTHS howto?

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?
>
> > something like this: aptitude search ~i | cut -d" " -f2
> > does this help you ?
>
> No.

So, if you only need package name:

aptitude search ~i | cut -d" " -f3

Regards,
Sergio Cuellar


--
"Meine Hoffnung soll mich leiten
Durch die Tage ohne Dich
Und die Liebe soll mich tragen
Wenn der Schmerz die Hoffnung bricht"
 
Old 01-09-2008, 07:48 PM
 
Default 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.
 
Old 01-09-2008, 08:05 PM
"Paul Csanyi"
 
Default 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


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-09-2008, 08:11 PM
"Paul Csanyi"
 
Default Vá: awk FIELDWIDTHS howto?

2008/1/9, Florian Kulzer <florian.kulzer+debian@icfo.es>:

> You can tell aptitude that you want a list of only the package names:
>
> aptitude -F%p search ~i

Thank you!

I should read better the aptitude man pages!

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


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-09-2008, 08:15 PM
"Paul Csanyi"
 
Default Vá: awk FIELDWIDTHS howto?

2008/1/9, judd@wadsworth.org <judd@wadsworth.org>:
> 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:

I don't know.

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

Thank you!

--
Regards, Paul Csanyi
http://www.freewebs.com/csanyi-pal/index.htm
 
Old 01-09-2008, 09:36 PM
Ken Irving
 
Default Vá: awk FIELDWIDTHS howto?

On Wed, Jan 09, 2008 at 08:48:38PM +0100, Paul Csanyi wrote:
> 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.

aptitude search ~i | awk '{print $2}'

Maybe that's what you want? I've used awk a lot, never looked at
FIELDWIDTHS, and have proabably never set NF. I'm not sure what you're
trying to acheive, but good luck with it!

Ken

>
> 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?
>
> > something like this: aptitude search ~i | cut -d" " -f2
> > does this help you ?
>
> No.
>
> --
> Regards, Paul Csanyi
> http://www.freewebs.com/csanyi-pal/index.htm

--
Ken Irving, fnkci+debianuser@uaf.edu


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-09-2008, 11:47 PM
Rick Pasotto
 
Default Vá: awk FIELDWIDTHS howto?

On Wed, Jan 09, 2008 at 08:48:38PM +0100, Paul Csanyi wrote:
> 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

This will give you what you want:

aptitude search ~i | awk '{ print substr($0,5,32) }'

--
"The Achilles' heel of authoritarianism is that the leader by the very
nature of his position is able to ignore the wisdom of anyone "below"
him--that is, anyone who stands between him and the real world. This is
what authority means: immunity from competence." -- Philip Slater
Rick Pasotto rick@niof.net http://www.niof.net


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-10-2008, 12:01 AM
David Jardine
 
Default Vá: awk FIELDWIDTHS howto?

On Wed, Jan 09, 2008 at 08:48:38PM +0100, Paul Csanyi wrote:
> 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 don't know aptitude, but that output can hardly constitute a
"record", since "busybox" is the 2nd field whereas "bzip2" is
the 3rd because of that "A".

> I try to get only the package name from the 2. field.

Which is what you've got: "A" is the second field.

> FIELDWIDTHS = " 4 32 "

I don't know awk, either (What the hell am I doing in this
thread ? :{) and I couldn't find FIELDWIDTH in the awk manpage,
but perhaps it doesn't do what you think it does. Perhaps it
just limits the length of a longer field for output.

> The given width for 1. field (4) should be right, but isn't.
> Awk give me the letter "A" as a 2. field. Why?

Because it is the second field, but since the lines returned
by that aptitude command are inconsistent in format I'm afraid
I can't think of anything you can do about it. If you know
what sort of things might appear where that "A" appears, you
could maybe insert something like

sed -r 's/ [A-Z] //g'

into your command.

>
> > something like this: aptitude search ~i | cut -d" " -f2
> > does this help you ?
>
> No.
>
> --
> Regards, Paul Csanyi
> http://www.freewebs.com/csanyi-pal/index.htm
>


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 01-10-2008, 12:57 AM
Bob McGowan
 
Default Vá: awk FIELDWIDTHS howto?

David Jardine wrote:

On Wed, Jan 09, 2008 at 08:48:38PM +0100, Paul Csanyi wrote:

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 don't know aptitude, but that output can hardly constitute a
"record", since "busybox" is the 2nd field whereas "bzip2" is
the 3rd because of that "A".



I try to get only the package name from the 2. field.


Which is what you've got: "A" is the second field.


FIELDWIDTHS = " 4 32 "


I don't know awk, either (What the hell am I doing in this
thread ? :{) and I couldn't find FIELDWIDTH in the awk manpage,
but perhaps it doesn't do what you think it does. Perhaps it
just limits the length of a longer field for output.


My man page says:

If the FIELDWIDTHS variable is set to a space separated list of
numbers, each field is expected to have fixed width, and gawk splits
up the record using the specified widths. The value of FS is ignored.





The given width for 1. field (4) should be right, but isn't.
Awk give me the letter "A" as a 2. field. Why?


Because it is the second field, but since the lines returned
by that aptitude command are inconsistent in format I'm afraid
I can't think of anything you can do about it. If you know
what sort of things might appear where that "A" appears, you
could maybe insert something like


sed -r 's/ [A-Z] //g'

into your command.


something like this: aptitude search ~i | cut -d" " -f2
does this help you ?

No.

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



The bottom line problem is that the aptitude output has a fixed
formatting, but the columns it "prints" are variable. So, given the
fixed formatting, any command that honors that would work:


aptitude search ~i | cut -c5-32 # NOTE! used -c, not -d" " -f2
aptitude search ~i |
sed 's/^....(................................).*$/1/'

That sed command remembers character 5 through 32 and replaces the whole
line with the remembered stuff. I'm not a 'sed' programmer, though, so
I'm sure there's a simpler way to specify repetition, I just didn't
bother to look it up.


I don't know if the following observation is a bug or a feature, but you
apparently need to specify the number of field widths you want, *plus
one*. Also, use the BEGIN keyword on code that needs to be "globally"
available or done just once. The original code will reassign
FIELDWIDTHS for every line of output. This code works as desired:


aptitude search ~i | awk 'BEGIN{FIELDWIDTHS = "4 32 1"};{print $2}'

--
Bob McGowan
 

Thread Tools




All times are GMT. The time now is 04:11 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org