Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ucsd!ucsdhub!esosun!seismo!uunet!tiamat!jim From: jim@tiamat.fsc.com (Jim O'Connor) Newsgroups: comp.unix.questions Subject: Re: Supressing new-lines in awk output Summary: use the printf() method Keywords: awk Message-ID: <372@tiamat.fsc.com> Date: 4 Feb 89 19:10:06 GMT References: <21638@conexch.UUCP> Organization: Filtration Sciences Corp., Chattanooga, TN Lines: 24 In article <21638@conexch.UUCP>, root@conexch.UUCP (Larry Dighera) writes: > Is there a way to supress the newline at the end of awk's print output? > Given: > awk '{print $1}' filename > Where filename contains: > field1.1 field1.2 > field2.1 field2.2 > field3.1 field3.2 > awk will print the first field of each record on a seperate line: > field1.1 > field2.1 > field3.1 > Is there a way to cause each "$1" to be printed with a space delimiter instead, awk ' {printf "%s ", $1} END { print }' filename should do the trick. The END action is needed or you won't get a newline at all. Just like printf() in the C library, the awk printf needs "\n" at the end of the format string if you want a newline. --jim