Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!killer!texbell!sw1e!uucibg From: uucibg@sw1e.UUCP (3929]) Newsgroups: comp.unix.questions Subject: Re: Supressing new-lines in awk output Keywords: awk Message-ID: <1277@sw1e.UUCP> Date: 9 Feb 89 15:48:46 GMT References: <21638@conexch.UUCP> <388@greens.UUCP> Reply-To: uucibg@sw1e.UUCP (Brian Gilstrap [5-3929]) Organization: Southwestern Bell Telephone Co Lines: 41 In article <388@greens.UUCP> matthew@sunpix.UUCP ( Sun NCAA) writes: >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? > >Try using awk's printf command. If you don't include a '\n' in the format >specifier, non will be printed. > >awk '{printf "%s ", $1} filename > Also, in the body for a BEGIN pattern, you can set the output record separator to nothing via: BEGIN { ... ORS = "" ; ... } I know this works for the new awk, and I'm not sure but I believe that it's one of the undocumented features of the standard awk (Note however, that the currently standard 'awk' will become 'oawk' in SysV.4 and the current 'nawk' will become the standard 'awk'). Note also that you can change ORS anywhere in the awk program, not just in BEGIN clauses. This is nice if you want to save the current separator and temporarly use something different, restoring the original value after you're through. >> Is there a way to cause each "$1" to be printed with a space delimiter > >Notice space in above example. A '\t' could also be used to insert a tab. > Similar to ORS above, OFS is the output field separator and can be set to whatever you like (e.g. '... OFS = "" ...' ). >Matthew Lee Stier (919) 469-8300| >Sun Microsystems --- RTP, NC 27560| "Wisconsin Escapee" >uucp: {sun, rti}!sunpix!matthew | Brian R. Gilstrap Southwestern Bell Telephone One Bell Center Rm 17-G-4 ...!ames!killer!texbell!sw1e!uucibg St. Louis, MO 63101 ...!bellcore!texbell!sw1e!uucibg (314) 235-3929 #include