Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 May 1996 22:03:26 +0200 (MET DST)
From:      J Wunsch <j@uriah.heep.sax.de>
To:        owensc@enc.edu
Cc:        freebsd-bugs@FreeBSD.org
Subject:   Re: bug in awk
Message-ID:  <199605242003.WAA23587@uriah.heep.sax.de>
In-Reply-To: <Pine.FBS.3.93.960524091252.252E-100000@dingo.enc.edu> from Charles Owens at "May 24, 96 09:27:26 am"

next in thread | previous in thread | raw e-mail | index | archive | help
As Charles Owens wrote:

>   ls -1 *.doc \
>     | awk '{FS="."; print "cp " $1 ".doc /usr/local/man/cat1/" $1 ".1" }'
> 
> This produces:
>   cp crc.doc.doc /usr/local/man/cat1/crc.doc.1
>   cp minirb.doc /usr/local/man/cat1/minirb.1

> Note the problem that the first line has.  This behavior is repeatable,

I think this is expected behaviour.  The first line has been parsed,
using the default FS value.  *After* parsing it, you're going to set
FS to a new value, so it will affect the next (and all following)
lines.

The correct ways to do it:

. use the -F . option, or

. use ``awk 'BEGIN {FS="."} {print "cp " $1 ...}' ''

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



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