Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!netnews.upenn.edu!jes From: jes@mbio.med.upenn.edu (Joe Smith) Newsgroups: comp.unix.questions Subject: Re: Strange behaviour of awk Message-ID: Date: 27 Feb 89 06:09:35 GMT References: <497@eutrc3.UUCP> Sender: news@netnews.upenn.edu Organization: University of Pennsylvania, Philadelphia, PA Lines: 33 In-reply-to: wsinkees@eutrc3.UUCP's message of 24 Feb 89 11:17:27 GMT > Is this a bug, or do I overlook some mechanism of awk? The AWK book says that "when one of $1, $2, etc., is changed, $0 is reconstructed using OFS to separate fields". So it's definitely a bug. However, unless you are using System V, you probably have old awk which may have bugs that have been fixed in new awk. Our (SunOS 4.0) old awk suffers the same bug. >2. Is there a direct way to get $2, $3, .... until the end of the line (record) > without the somewhat dirty change of $1? This was my original problem. You could just concatenate the fields with a simple loop: x = "" for (f = 2; f < NF; ++f) # skip $1 x = x " " $f # fields separated by space print x That won't preserve the spacing from the input line, but I don't think *any* awk will do that. If the spacing is important, maybe you could use sed: sed 's/^ *[^ ]* *//' file -- jes@mbio.med.upenn.edu University of Pennsylvania Dept. of Biochemistry and Biophysics 233 Anatomy-Chemistry Philadelphia, PA 19104-6059 (215) 898-8348