some questions about awk

zben at umd5.UUCP zben at umd5.UUCP
Tue Feb 17 13:19:32 AEST 1987


In article <254 at herman.UUCP> alan at herman.UUCP (Alan Kiecker) writes:

> 1. Is there any way to send control codes to the printer from within
>    an "awk" program. I have not been able to find any way to output
>    binary, i.e. non-ascii, data from an "awk" program. Both print
>    and printf insist on converting to ascii.

Gosh, it's almost too easy.  Use "printf" with a "%c" format and give it
a bare integer!  Here's a quickie I just whomped up to insert formfeeds
every 66 lines for printing "man" entries out on an IBM 3800 laserprinter.

awk 'BEGIN { fnam = FILENAME }
(fnam!=FILENAME) { NR=1 ; fnam=FILENAME ; printf "%c\n",12 }
{ print }
(65==((NR-1)%66)) { printf "%c\n",12 }' $*

Needless to say the 12 is the linefeed.  The "fnam" stuff is in case you
give it multiple files, it wants to reset (and pageup) between files.
There is a bug if you feed it the same file(name) twice.  Any REAL awk
freaks out there know a solution to this?  Kernighan and Pike use this
same trick on page 121, with the same bug...
-- 
                    umd5.UUCP    <= {seismo!mimsy,ihnp4!rlgvax}!cvl!umd5!zben
Ben Cranston zben @ umd2.UMD.EDU    Kingdom of Merryland UniSys 1100/92
                    umd2.BITNET     "via HASP with RSCS"



More information about the Comp.unix.questions mailing list