Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Feb 2007 16:00:28 GMT
From:      Kris Kennaway <kris@obsecurity.org>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: misc/109047: cut utility reads off by one place when day (date) is a double digit
Message-ID:  <200702121600.l1CG0Sh8023888@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/109047; it has been noted by GNATS.

From: Kris Kennaway <kris@obsecurity.org>
To: Tim <cyberlord@cyber-wizard.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/109047: cut utility reads off by one place when day (date) is a double digit
Date: Mon, 12 Feb 2007 10:57:02 -0500

 On Sun, Feb 11, 2007 at 02:00:26PM +0000, Tim wrote:
 
 > When the day (date) reaches double digits the cut utility/program somehow reads the field as off by one. I'm not sure if this is a problem with the auth.log or with cut itself but my bet is on cut. 
 > 
 > I have a script that reads auth.log and filters out bad login attempts and writes to hosts.allow. When the date reaches double digits I have to adjust my script accordingly.
 > 
 > Here is the offending line in my script.
 > 
 > for IP in `grep sshd /var/log/auth.log|grep "illegal user"|cut -d " " -f14` 0.0.0.0; do
 > 
 > I have to change the -f14 to -f13 during double digit days and then again when the month rolls over set it back to -f14.
 
 I think this is a bug in your expectation of how to use cut :-)
 
 As you have found (also how it is documented to work), cut treats each
 instance of the delimiter (" ") as separating a new field, so when
 spacing changes so does its idea of field counting.  This is by
 design.
 
 If you want to extract a word without worrying about whitespace, use a
 different tool, a convenient one is
 
 awk '{print $14}'
 
 Kris



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200702121600.l1CG0Sh8023888>