Supressing new-lines in awk output

3929] uucibg at sw1e.UUCP
Fri Feb 10 01:48:46 AEST 1989


In article <388 at greens.UUCP> matthew at sunpix.UUCP ( Sun NCAA) writes:
>In article <21638 at conexch.UUCP>, root at 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 = "<silly field separator string>" ...' ).

>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 <std_disclaimers.h>



More information about the Comp.unix.questions mailing list