Path: utzoo!attcan!uunet!mcvax!hp4nl!eutrc3!wsinkees From: wsinkees@eutrc3.UUCP (Kees Huizing) Newsgroups: comp.unix.questions Subject: Strange behaviour of awk Summary: The value of $0 seems to depend on whether it has been printed Keywords: awk Message-ID: <497@eutrc3.UUCP> Date: 24 Feb 89 11:17:27 GMT Reply-To: wsinkees@eutrc3.UUCP (Kees Huizing) Organization: Eindhoven University of Technology, The Netherlands Lines: 31 References: Sender: In the use of the UNIX filter "awk" I encountered the following problem. I want to save a line of input except the first field into a variable for later use. So I empty the first field and then assign the modified record to the variable. But how curious! When I try the test case {$1 = "" ; x = $0 ; print x} on the input Tom Dick Harry I just get : Tom Dick Harry Testing the value of $0 by printing it {$1 = "" ; print} yields the expected output Dick Harry So my solution is: {$1 = "" ; print >"/dev/null" ; x = $0 ; print x} And this works!, yielding Dick Harry Now I have two questions: 1. How can the value of $0 depend on whether it has been printed or not? Is this a bug, or do I overlook some mechanism of awk? 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. P.S. We have Ultrix 2.2 (appr. Unix BSD); I don't know how "new" our awk is. Kees Huizing wsinkees@eutrc3.UUCP -or- wsdckees@heitue5.BITNET Dept. of Math. and Comp. Sc. - Eindhoven Univ. of Techn. - Eindhoven T H E N E T H E R L A N D S