awk FIELDWIDTHS howto?

2008-01-09 Thread Paul Csanyi
Hello!

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

Any advices will be appreciated!

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


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: awk FIELDWIDTHS howto?

2008-01-09 Thread Sergio Cuéllar Valdés
2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
 Hello!

 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

Hello,

something like this:   aptitude search ~i | cut -d  -f2

does this help you ?

Best 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


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread Paul Csanyi
2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
 2008/1/9, Paul Csanyi [EMAIL PROTECTED]:

  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



Re: Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread Sergio Cuéllar Valdés
2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
 2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
  2008/1/9, Paul Csanyi [EMAIL PROTECTED]:

   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



Vá: Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread Paul Csanyi
2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
 2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
  2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
   2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
 
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?

 So, if you only need package name:

  aptitude search ~i | cut -d  -f3

It is cut, not awk.
Howewer, it is not god. The output file contains empty lines
besides of the package names.

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



Re: Vá: Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread Sergio Cuéllar Valdés
2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
  So, if you only need package name:
 
   aptitude search ~i | cut -d  -f3

 It is cut, not awk.
 Howewer, it is not god. The output file contains empty lines
 besides of the package names.

No blank lines  :   aptitude search ~i | cut -d  -f3 | sed '/^$/d'

done

yes, no awk


-- 
Meine Hoffnung soll mich leiten
Durch die Tage ohne Dich
Und die Liebe soll mich tragen
Wenn der Schmerz die Hoffnung bricht


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Vá: Vá : awk FIELDWIDTHS howto?

2008-01-09 Thread Florian Kulzer
On Wed, Jan 09, 2008 at 14:16:38 -0600, Sergio Cuéllar Valdés wrote:
 2008/1/9, Paul Csanyi:
   So, if you only need package name:
  
aptitude search ~i | cut -d  -f3
 
  It is cut, not awk.
  Howewer, it is not god. The output file contains empty lines
  besides of the package names.
 
 No blank lines  :   aptitude search ~i | cut -d  -f3 | sed '/^$/d'
 
 done
 
 yes, no awk

You can tell aptitude that you want a list of only the package names:

aptitude -F%p search ~i

-- 
Regards,| http://users.icfo.es/Florian.Kulzer
  Florian   |



Re: Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread judd
On  9 Jan, Sergio Cuéllar Valdés wrote:

 2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
 2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
  2008/1/9, Paul Csanyi [EMAIL PROTECTED]:

   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   [EMAIL PROTECTED]   | 
|   Wadsworth Center - ESP |
|   P. O. Box 509518 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.




Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread Paul Csanyi
2008/1/9, Daniel Mahoney [EMAIL PROTECTED]:

 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 [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread Paul Csanyi
2008/1/9, [EMAIL PROTECTED] [EMAIL PROTECTED]:
 On  9 Jan, Sergio Cuéllar Valdés wrote:

  2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
  2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
   2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
 
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



Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread Paul Csanyi
2008/1/9, Florian Kulzer [EMAIL PROTECTED]:

 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 [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Vá : awk FIELDWIDTHS howto?

2008-01-09 Thread Ken Irving
On Wed, Jan 09, 2008 at 08:48:38PM +0100, Paul Csanyi wrote:
 2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
  2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
 
   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, [EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Vá : awk FIELDWIDTHS howto?

2008-01-09 Thread David Jardine
On Wed, Jan 09, 2008 at 08:48:38PM +0100, Paul Csanyi wrote:
 2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
  2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
 
   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 [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Vá : awk FIELDWIDTHS howto?

2008-01-09 Thread Rick Pasotto
On Wed, Jan 09, 2008 at 08:48:38PM +0100, Paul Csanyi wrote:
 2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:
  2008/1/9, Paul Csanyi [EMAIL PROTECTED]:
 
   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[EMAIL PROTECTED]http://www.niof.net


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Vá: awk FIELDWIDTHS howto?

2008-01-09 Thread Bob McGowan

David Jardine wrote:

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

2008/1/9, Sergio Cuéllar Valdés [EMAIL PROTECTED]:

2008/1/9, Paul Csanyi [EMAIL PROTECTED]:

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



smime.p7s
Description: S/MIME Cryptographic Signature