Working with files

Working with files in MTS can seem quite different compared to other systems. There are features missing that are considered as standard today - directories, automatic creation of new files - but there are also features in MTS that are more powerful than Unix or Windows.

For example, the single command

$copy A(2,10,2)+B(*l)@bkwd C

copies the even numbered lines from 2-10 from A together with all lines from B in reverse order and stores in C. These operators apply to the file, not the command, so can be used on any MTS command line where they make sense.

Types of files

The MTS documentation refers to FDnames - this means either a filename or a pseudodevice name. (Update: as Jeff notes in his comment below, FDnames also include devices and other modifiers such as line number ranges.)

Line files

By default files in MTS are line orientated - an individual line can be accessed directly rather than having to read from the start of the file. Each line can be up to 32k long. Line numbers can be negative and can contain up to three digits after the decimal point; the range allowed is -2147483.648 to 2147483.647.

You can specify part of a file by using (start, end, increment) after the file name, where each component is optional. You can use *f to refer to the first line in the file and *l for the last line. Some examples:

File options

You can add extra options while processing files by using operators starting with @. Some useful options:


You can explicitly concatenate two or more files using the + operator, eg copy a+b c.

There is also an implicit concatenation similar to the way the C language handles #include preprocessor directives, but working on all types of file.

This operation depends on the contents of the file. If a file contains a line such as $continue with b then the contents of b are effectively inserted at that point and the rest of the current file is ignored. A line such as $continue with b return will include all of file b at that point and then return to processing the rest of the current file.

Further Reading

See the ‘Files & Devices’ chapter in MTS Volume 1 for a full description.

I will come back to the topic of pseudodevices in a future post, which will also cover how to do redirection of file input and output.


comments powered by Disqus