[comp.unix.questions] some questions about awk

alan@herman.UUCP (02/13/87)

I am trying to write an application using "awk" and have run into a
couple of problems:

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.

2. Is there a way to read data from stdin? My application is interactive
   in that it must receive direction from the user via the keyboard
   at various points. The shell "read" command capability would be
   sufficient.

3. Is there a way to execute shell commands?

In advance, thanks for your help.
-- 
Al Kiecker			UUCP: 	ihnp4!clyde!herman!alan
Unisys - Computer Systems Div.		meccts!herman!alan
Eagan,MN			AT&T:	(612)681-6475

zben@umd5.UUCP (02/17/87)

In article <254@herman.UUCP> alan@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"

pdg@ihdev.UUCP (02/18/87)

In article <1446@umd5> zben@umd5.umd.edu (Ben Cranston) writes:
>awk 'BEGIN { fnam = FILENAME }
>(fnam!=FILENAME) { NR=1 ; fnam=FILENAME ; printf "%c\n",12 }
>{ print }
>(65==((NR-1)%66)) { printf "%c\n",12 }' $*
>There is a bug if you feed it the same file(name) twice.  Any REAL awk
>freaks out there know a solution to this?  

In the REAL awk on my machine , just test  FNR == 1  (Line number in
the current file). But as has been mentioned before, this will not
become available until the next release of SVR3.  Or of course you
could parse through the file list yourself by using ARGV[].
This probably didn't help anyone at all, but its nice to know what to
look forward to in the future.



-- 

Paul Guthrie
ihnp4!ihdev!pdg			This Brain left intentionally blank.