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
-
Permanent files need to be created explicitly. Maximum name length is 12 characters and as in Unix a file extension is entirely optional. Permanent files are private to each user unless access is explicitly granted to another user. If access is granted you can use the notation
user:file
to refer to the file. -
Temporary files must start with
-
and names must be 8 characters or less. These do not need to be explicitly created but are automatically destroyed by the system when you log out or a batch job that creates them finishes. -
Public files must begin with a
*
and their names must be 16 characters or less. These are generally system wide programs or libraries. -
It’s also possible to refer to a pseudodevice instead of a file. These start and end with
*
- an example was seen in the up and running guide,copy *source* file
, which copies input from the keyboard to a file.
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:
A(5,10)
- all lines between 5 and 10 inclusive from AA(5)
- all lines from 5 onwards from AA(*f, 5)
all lines from start of file to line 5 inclusiveA(1,10,2)
- lines 1, 3, 5, 7 and 9 from A
File options
You can add extra options while processing files by using operators starting with @
. Some useful options:
@uc
converts the file to upper-case@trim
removes trailing spaces@bkwd
processes the file in reverse order
Concatenation
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.