midriff: midriff

dynamic content system
| Manual page for midriff(TDH)

## Name

midriff - command line script interpreter

## Synopsis

`midriff` options`` scriptfile`[`varvalue-pairs`]
`

## Description

The midriff utility executes scriptfile and writes the results to standard output. The midriff utility may be used as a template processor to generate a document in one pass, or it may be used as a filter, to generate results based on an input stream of records.`` For CGI uses, the similar mrcgi program should be used instead.``

scriptfile should be a script following the midriff script syntax The midriff command line utility supports all directives except those that are specific to CGI and CGI forms.``

The order of command line arguments matters; options should come first, then the scriptfile, then any varvalue-pairs.``

## Options

-dp

  Data processing mode. This is a convenience option which is equivalent to `-f -u -n`, often used when processing data (as opposed to producing a presentation document).``

-f

  Filter mode. Read data records on stdin and execute the script repeatedly, once per incoming record.`` Script may reference incoming data fields using field numbers (e.g. ).`` Or, with `-h` or `-H` using field names from the field name header (e.g. @balance).`` Unless -u is used, Embedded underscores in data fields will be converted to space, except when `-u` is used.`` NULL fields will be converted to zero length strings, unless `-n` is used.``

-u

  Leave embedded underscores in fields when reading data. Normally embedded underscores are converted to a space before interpreting the script.``

-n

  Show NULL fields. Normally each null is converted to "" before interpreting the script.``

-h

  Header mode. Implies `-f`.`` Incoming data records have fields named in the first non-comment non-blank line, separated by white space.

-H

  Same as -h but field name header is written to output.`` If no records are written then header is not written.``

-o

  Output each data record to stdout after it is processed. Data records may be conditionally printed to stdout by using the internal variable _PRINTDATA (see below).

-s

  Show last line executed in the event of an error.``

-d

  Hide directives that midriff doesn't know about. Normally these are shown.`` A directive is considered to be any line having a first non-whitespace character of pound sign (#).``

-t

  Incoming fields are tab delimited, and if -o or _PRINTDATA is used, output fields are tab delimited.`` May also be set using project config file `tabfields` attribute.``

-ver or -?

  Print the midriff version number.`` The version number is also available to scripts in the midriff variable MIDRIFF_VERSION.``

## Varvalue pairs

These may follow the scriptfile on the command line.`` The varvalue pair sets the given variable to the given value before invoking the script. Example: `ID=0202`

## Exit code

The #exit directive may be used to generate a midriff exit code which can be captured by the invoking shell.``

## Special variables and operators

The variable _PRINTDATA is pre-declared. Your script can set it to 1 if you wish to print the input record selectively.``

If you are using midriff to process data records, you can use constructs such as @1 or @12 to access incoming data fields.`` You can also set these fields, eg. `#set 7 = hello`.``

The special operator `<line>` may be used to print an input data record verbatim.`` It must be used at the beginning of the line, and must be alone on the line.`` This may be useful when processing white-space formatted data, or when it is desired to print an entire data record to stdout, without having to enumerate all the fields. Normally, incoming data is parsed into fields which makes it impossible to preserve space formatting.`` The <line> operator gets around this problem.``

## EXAMPLES

1. Execute the script myfile.script. The variables ID and CLINIC would be defined and set to the given values before executing the script.`` The script retrieves related data (a name) for presentation, using $dba_get().``

  `midriff myfile.script ID=02930 CLINIC=02 > out`

2. Read a stream of records having field names in the first line (header), and produce a brief report for each record:

  `cat data | midriff -h myscript`

## NOTES

Directives that are not recognized will be ignored and echoed to standard output, unless -d is used.``

#cgivar variables may be set from the command line as var-value pairs.``

## ENVIRONMENT

SHSQL_DB = the full path name of the project directory containing a config file.`` This is generally optional.``

## SEE ALSO

mrcgi - a version of midriff designed to run in cgi mode, with support for things like CGI forms.``

dynamic content system
Copyright Steve Grubb

Markup created by unroff 1.0, `` `` September 19, 2003.