AIX 4.x Print Filters


About this document
    Related documentation
Examples of AIX filters
How to use a filter from a virtual printer
Examples of user written filters
Using the pr filter
Using the enscript filter
Using the asa or fpr FORTRAN filter
Using the troff filter
Using the tr filter

About this document

Filters in UNIX are generally programs that read from standard in (stdin), write to standard out (stdout), and somewhere in the middle modify the data in some way. Filters can be run directly from the command line, from a shell script, or from within a virtual printer. This document covers how to use a filter from a virtual printer, explains some filter details that are available with AIX, and provides some tips on writing your own filters.

This document applies to AIX version 4.x.

Related documentation

The product documentation library is also available through the following link: Pubs/index.html

NOTE: The AIX online product documentation has a sample C filter for adding carriage returns to line feeds.

Examples of AIX filters

Examples of filters that are a part of AIX include:

This filter formats ASCII data into pages, adds page numbers, and can provide print rotation and page numbers. It is very similar to piobe formatting.

asa or fpr
This filter interprets the carriage control characters in column one, sometimes known as FORTRAN formatting. Although this filter goes by two names, there is only one filter.

nroff, troff, psroff, hplj, psc, tbl, pic, eqn, grap
These filters are for formatting xroff data to/from ditroff format. These filters allow a tagged file to create a formatted document that supports multiple fonts, tables, pictures, equations, and the like.

This filter converts ASCII text data to PostScript.

This filter translates ASCII text from one character to another.

How to use a filter from a virtual printer

Filters are generally set up in a virtual printer to run before the data goes to the formatting pipeline. In fact, you can implement a filter even when the virtual printer is set in pass through mode and when it does not use either the ci (initialization) or cr (reset) sequences.

The trigger that turns on a particular filter is the _f attribute or the -f command line flag. This attribute allows a single character value. This character is used to point to an attribute that begins with an f and ends with the specified character that contains the name of the program to run. For example if _f=l, then the filter program used will be listed in fl. The program name is specified by setting fl=/full/path/name.


If you are using a korn shell script, use f1=/bin/ksh /usr/local/bin/myfilt

Setup at AIX 4

The steps to set this up in AIX 4 are:

Examples of user written filters

User written filters should read from stdin and write to stdout. The following are simple filters used to add carriage returns to line feeds.

Example filter in C

/* lfilt.c,  compile 'cc -o lfilt lfilt.c'                      */
/* Program to provide a filter to add \r to every \n in a file
   This is needed for some printers when using passthrough
      mode */
#include        "stdio.h"
#include        "termio.h"
#include        "termios.h"
int main(void)
        int             c;
        while ( (c = getc(stdin)) != EOF)
                if (c=='\n') putc('\r',stdout);
                putc(c, stdout);

Example sed filter

Be sure to put the sed program in the fl attribute as follows:

In this example the sed script is called rmcr and is in /usr/local/bin.

This sed script is a single line

Another solution is to use the tr filter program to translate one character to another. See the man page of tr for details.

Using the pr filter

The pr filter is a program that does basic text formatting for printing such as adding carriage returns to line feeds, adding page numbers, and even creating 2-up documents.

When the qprt -fp flag is used, the pr filter is called automatically. This will add the file name and page numbers automatically to each page. This is useful when comparing files. The printed file name on each page is helpful. You can set a title page for the pr filter from smit chpq under the Default Print Job Attributes.

The virtual printer attribute, fp, calls pr and uses the -l and -w flags to determine the length and width of the page for adding carriage returns and line feeds.

To use pr to create a 2-up page that is landscape with two columns, use the command:

  pr -l 60 -w 172 -2 <filename> | qprt -z+ -dp -p17splp
The output will look similar to this:

Using the enscript filter

The enscript filter is a program than converts ASCII text to PostScript. See the man pages of enscript for details on the flags.

This filter will be called automatically when you send text data to a PostScript virtual printer and the Automatic Detection of Data Type is set to yes. You can also force it to be called by sending the -da flag to qprt as follows:

  qprt -da -P<ps_queue> <text_file>

When used with the PostScript queue, many of the standard ASCII virtual printer flags are automatically passed on to enscript after being converted to enscript flags. For example when you use the qprt -z+ flag to print a file in landscape, this is passed to enscript as -r for rotate.

The font used by enscript can be changed by using the qprt -s flag as shown here:

  qprt -da -sCourier-Bold -P<ps_queue> <text_file>
When using enscript from the command line, 2 column prints can be created by using the following command examples:
  enscript -dps39 -2r filex
  enscript -2rG -dsp filename

Using the asa or fpr FORTRAN filter

The asa and fpr commands are really the same command. They are the default ff attribute for many virtual printers. This means that they will be called by the qprt -ff flag. This filter is usually used when the program has placed carriage control characters in column one of the file as is the tradition from mainframe card punch days.

The asa and fpr commands print FORTRAN files to conform to AIX line-printer conventions. Both commands work like a filter to transform files formatted according to FORTRAN carriage control conventions into files formatted according to AIX line-printer conventions.

Both commands read the first character of each line from the input file, interpret the character, and space the line according to the definition of the first character. If the first character is a blank, a 0 (zero), a dash (-) , a 1 (one), or a plus sign (+), either command does the following:

The commands interpret a blank line as if its first character is a blank and delete a blank that appears as a carriage control character. It treats lines that begin with characters other than the defined control characters as if they begin with a blank character. The first character of a line is not printed. If any such lines appear, an appropriate diagnostic appears in the standard error.

NOTE: Results are undefined for input lines longer than 170 characters.

Using the troff filter

The set of ~roff commands includes troff, nroff, psc, psroff, hplj and others. These commands are designed to handle a markup language that has long been used for typesetting and creating books. It is not used as much today, but can still be useful when printing things like man pages. For more information, read the man pages for the individual commands.

To use this filter, the Text Formatting Tools must be installed from fileset bos.txt.ts.

The qprt -fn flag is used to call the ditroff filter. You can see how this is called by looking at the fn attribute of the virtual printer. The contents of this will vary depending on the type of printer being used. For a PCL printer, this will call the hplj filter program as shown here.

ditroff filter
fn = { if [[ ! -x /usr/bin/hplj ]]; then %Ide/piomsg -c -s 1 -n 804
 "Error\072 The /usr/bin/hplj command was not found."; exit 1; fi;
/usr/bin/hplj; }%ip
 '{ if [[ ! -x /usr/bin/hplj ]]; then '
 %Ide          INCLUDE: (Directory Containing Miscellaneous Modules)
 '/piomsg -c -s 1 -n 804 "Error\072 The /usr/bin/hplj command was
  not found."; exit 1; fi; /usr/bin/hplj; }'
 %ip           Force Attribute ip as Main Pipeline

The psroff command can be entered from the command line to format man pages for PostScript printers as follows:

  psroff -man  /usr/local/man/man1/pdf2ps.1

Hint: The man page from this example is a public domain program that is a filter for converting Adobe Acrobat pdf files to PostScript and could be used as a user filter.

Using the tr filter

The tr filter can be used to convert one character or string to another. This could be used as a spell correcting technique, a technique to remove null characters, or it could be used to change all lower case letters to upper case.

It can also be used for Y2K conversion by converting all Y characters to K's. (A little humor)

For example to print a file in all upper case letters use:

  cat /etc/motd | tr 'a-z' 'A-Z' | qprt
To replace every nonprinting character, other than valid control characters, with a ? (question mark), enter:
  tr -c '[:print:][:cntrl:]' '[?*]' < <textfile> > <newfile>

This filter can be added to a virtual printer as a user filter as described above. There is also a similar command from the BSD UNIX heritage called trbsd.


This document has described some of the filters that come with AIX and some uses for them. A number of filters are also available through the public domain to perform tasks such as converting from one format to another. One of the most popular is a program called GhostScript or often referred to as gs. This filter can be used to print some PostScript files to PCL printers.

[ Doc Ref: 92187555516324     Publish Date: Oct. 02, 2000     4FAX Ref: 6500 ]