Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!apple!vsi1!ubvax!mrspoc!itkin From: itkin@mrspoc.UUCP (Steven M. List) Newsgroups: comp.unix.questions Subject: Re: Supressing new-lines in awk output Keywords: awk Message-ID: <4569@mrspoc.UUCP> Date: 4 Feb 89 23:05:43 GMT References: <21638@conexch.UUCP> Reply-To: itkin@mrspoc (Steven List) Organization: Transact Software, Inc., Mt. View, CA Lines: 28 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 >... > Is there a way to cause each "$1" to be printed... > such that the output would look like: > > field1.1 field2.1 field3.1 > Yup - use the "printf" function instead of "print". "printf" takes arguments like the C language function to permit more advanced formatting of your output. To solve this problem, use awk '{printf "%s ",$1}' filename This will print the first field of each record followed by a space. To include the newline at the end of the entire list, use the following variant: awk '{printf "%s ",$1}END{printf "\n"}' filename -- : Steven List @ Transact Software, Inc. : {apple,coherent,limbo,mips,pyramid,ubvax}!mrspoc!itkin : Voice: (415) 961-6112