Awk error redirection - (nf)

liberte at uiucdcs.UUCP liberte at uiucdcs.UUCP
Fri May 4 11:27:00 AEST 1984


#N:uiucdcs:39300009:000:1475
uiucdcs!liberte    May  3 20:27:00 1984

I received the following (edited) letter which I couldnt respond to via mail.
I thought the solution to Don's awk problem was general enough to post.

----------------------
>From tekig1!dont%tektronix.csnet at csnet-relay.csnet Wed May  2 18:45:33 1984
Via:  Rand; 2 May 84 18:45-CDT
  How the #$%&^@!!%$ do you get AWK to print something on the error output?
Don Taylor  tektronix!tekig1!dont
----------------------

Try something like this awk.prog:

{print "Error output: " $0 | "tee >&2"}
{print "Standard out: " $0 }

In csh:	
	awk -f awk.prog		     # causes both to go to terminal.
	awk -f awk.prog >& awk.out   # both go to awk.out
	awk -f awk.prog > awk.out    # puts errors to terminal, 
					standard output to awk.out
>>>>>	(awk -f awk.prog > awk.out) >& awk.error
		# puts standard output in awk.out and errors in awk.error
	
In sh, replace  '>& file' with '> file 2>&1' to get the same results.

So there is a difference.  I am not sure that '| "tee >&2"' is the best way
to do it.  This trick uses the bourne shell output redirection inside awk.  
It would be nice to have more general IO redirection within awk as long as
they have gone to so much trouble to have any (> >> and |).

Why dont they just document some of these handy things 
instead of making us figure it out individually like some adventure game?
It is fun to discover tho...


Daniel LaLiberte,  U of Illinois, Urbana-Champaign, Computer Science
{moderation in all things - including moderation}



More information about the Comp.unix mailing list