misc/109047: cut utility reads off by one place when day (date)
is a double digit
Kris Kennaway
kris at obsecurity.org
Mon Feb 12 16:00:28 UTC 2007
The following reply was made to PR bin/109047; it has been noted by GNATS.
From: Kris Kennaway <kris at obsecurity.org>
To: Tim <cyberlord at cyber-wizard.com>
Cc: freebsd-gnats-submit at 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
More information about the freebsd-bugs
mailing list