newform(1) newform(1)
NAME
newform - change the format of a text file (new format)
SYNOPSIS
newform [option ...] [file ...]
DESCRIPTION
The newform command can be used to reformat text files or input lines
that are read in from the standard input.
newform reformats input text lines in accordance with the specified
command-line options and then reproduces them on the standard output.
OPTIONS
No option specified:
newform copies all input lines to the standard output unmodified.
Options must be entered individually, separated from one another by
blanks (see EXAMPLES). Command-line options are sequentially processed
in the order specified. They may appear in any order, but the sequence
in which they are entered is significant. This means that option
sequences such as -e15 -160 and -160 -e15 will produce different
results.
Except for -s, options may be repeated as often as required.
Options may also be intermingled with optional file names. The effect
is the same as when all options precede file names.
Options are applied to all files on the command line.
Expanding tabs to spaces
-i[tabspec]
Input tab specification. This option can be used to expand tab
characters to spaces, according to the list of tab stops speci-
fied in tabspec. newform then converts each tab in the input line
to the appropriate number of spaces so that the next character is
located at a tab stop (see Example 1).
Page 1 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
tabspec not specified:
The default value for tabspec is -8, which means that newform
assumes tab stops in columns 1, 9, 17, 25, etc.
tabspec specified:
tabspec may be specified as any of the following values:
-n, -0;
n1,n2,...;
-a, -a2, -c, -c2, -c3, -f, -p, -s, -u;
--, --name.
-n newform assumes tab stops in columns 1, 1+n, 1+2*n, 1+3*n
etc.
n is an integer greater than or equal to 1.
-0 newform expects no tabs; however, if any are found in the
input line, they are converted to one space each. The argu-
ment -i-0 thus yields the same result as -i-1.
n1,n2,...
Tabs are assumed in columns n1, n2, etc.
n1, n2, etc. are integers greater than or equal to 1. If you
enter a plus sign (+) before one of the numbers, the value
that follows it is added to the last specified number, and
the total is used as the new tab stop. The numbers must be
entered in ascending order and be separated by commas. One
or more numbers (to a maximum of 40) may be specified.
-a Equivalent to the tab stop list 1,10,16,36,72
(for Assembler; applicable on some mainframes)
-a2 Equivalent to the tab stop list 1,10,16,40,72
(for Assembler; applicable on some mainframes)
-c Equivalent to the tab stop list 1,8,12,16,20,55
(for COBOL; normal format)
-c2 Equivalent to the tab stop list 1,6,10,14,49
(for COBOL; compact format)
Page 2 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
-c3 Equivalent to the tab stop list
1,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62,67
(for COBOL; compact format with more tab stops than with
-c2)
-f Equivalent to the tab stop list 1,7,11,15,19,23
(for FORTRAN)
-p Equivalent to the tab stop list
1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61
(for PL/1)
-s Equivalent to the tab stop list 1,10,55
(for SNOBOL)
-u Equivalent to the tab stop list 1,12,20,44
(for Assembler; applicable on some mainframes)
-- newform assumes that the tab specification is to be found in
the first line read from the standard input. The tab speci-
fication must have the following format:
<:ttabspec d:>
--name
The tab specification is looked for in the first line of the
file called name. It must have the following format:
<:ttabspec d:>
Converting spaces to tabs
-o[tabspec]
Output tab specification. This option can be used to convert
spaces to tabs, according to the tab stop list specified in
tabspec. If one or more spaces precede these tab stops, newform
converts these spaces to one tab character (see Example 2).
Page 3 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
tabspec not specified:
The default value for tabspec is -8, which means that newform
assumes tab stops in columns 1, 9, 17, 25, etc.
tabspec specified:
The tab specifications are the same as for -i. If you enter a
value of -0 for tabspec, spaces will not be converted to tabs.
Print tab specification
-f (format line) newform writes the tab specification format line on
the standard output before displaying any other lines.
The tab specification has the following format:
<:ttabspec d:>
The value printed for tabspec will correspond to the format
specified in the last -o option. If you have not specified a
value with the -o option or have omitted it entirely, the default
value of -8 is printed for tabspec.
Caution:
If option -f is used, and the last -o option specified was -o--,
preceded by either -o-- or -i--, the tab specification format
line will be incorrect.
Example: newform ... -i-- ... -o-- -f file
Placing the first field at the end of a line
-s (shear off) newform shears off all characters in the input line
up to and including the first tab.
If only 8 characters or less (excluding the first tab) are
sheared off, all these characters (with the exception of the
first tab) are placed at the end of the line.
If more than 8 characters (excluding the first tab) are sheared
off, the eighth character is replaced by an asterisk; the follow-
ing characters are deleted. The first tab is always deleted.
Interaction with other options:
When the -s option is processed, newform shears off the charac-
ters at the start of the input line and saves them internally
until all other options specified have been applied to that line.
Only then are the characters added to the end of the processed
line.
Page 4 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
Caution:
When you specify the -s option, newform expects all input lines
to contain a tab character.
Truncating and extending lines
-l[n]
The effective line length is set to n characters, where n is an
integer greater than or equal to 1.
The -l option is only meaningful in combination with options -b,
-e, -p, or -a.
n not specified:
The effective line length is set to 72 characters.
-l[n] not specified:
The effective line length defaults to 80 characters.
Caution:
Tabs and backspaces are considered to be one character each; how-
ever, the -i option can be used to expand tabs to a specified
number of spaces.
-b[n]
(beginning) If the length of the input line exceeds that of the
effective line length (see option -l), newform truncates the
first n characters from the beginning of the line.
n is an integer greater than or equal to 1.
n not specified:
The number of characters needed to obtain the effective line
length are truncated from the beginning of the line.
-e[n]
(end) If the length of the input line is greater than the effec-
tive line length (see option -l), newform truncates the last n
characters from the end of the line.
n is an integer greater than or equal to 1.
n not specified:
The number of lines needed to obtain the effective line length
are truncated from the end of the line.
Page 5 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
-ck The character used for padding is changed to k, where k is any
printable ASCII character.
The -c option is only meaningful in combination with the -p or -a
options.
-c not specified:
The default character for k is a space.
-p[n]
(prefix) If the length of the input line is less than the effec-
tive line length (see option -l), newform prefixes n padding
characters (see option -c) to the beginning of the line.
n is an integer greater than or equal to 1.
n not specified:
newform prefixes the number of characters required to obtain the
effective line length.
-a[n]
(append) If the length of the input line is less than the effec-
tive line length (see option -l), newform appends n padding char-
acters (see option -c) to the end of the line.
n is an integer greater than or equal to 1.
n not specified:
The number of characters required to obtain the effective line
length is appended to the end of the line by default.
file Name of the text file to be reformatted.
If you specify more than one file, the options will be applied to
all files on the command line.
file not specified:
newform reads from the standard input.
ERROR MESSAGES
All the errors described below cause the program to exit.
not -s format
You have called newform with the -s option, but one of the input lines
does not contain a tab character.
can't open filename
Page 6 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
The input file filename cannot be opened, possibly because it does not
exist or because you have no permission to access it, etc.
internal line too long
A line exceeds 512 characters after being expanded in the internal
work buffer.
tabspec in error
The tabspec argument that you specified with the -i or -o option does
not have the correct format.
tabspec indirection illegal
You have called newform with the -i--, -o--, -i--file, or -o--file
option; however, the tab specification that was subsequently read by
newform from the standard input or from file contained another tabspec
in the form -i--, -o--, -i--file, or -o--file. This is not permitted.
In other words, a tabspec read from a file (or standard input) may not
contain a tabspec referencing another file (or standard input).
EXAMPLES
Converting tabs to spaces: option -i
Example 1
The contents of file are:
red <TAB> green
There is only one tab between the words red and green. The command od
can now be used to check the file contents; od displays tabs and new-
line characters as well:
$ od -c file
0000000 r e d \t g r e e n \n
0000012
0000012 indicates the number of characters contained in file in octal
notation.
Compare the output of cat and newform -i:
$ cat file
red green
$ newform -i file
red green
The word green begins in column 9 in both cases. Although it appears
that newform -i has not changed the contents of the file, the command
od shows that the tab character has in fact been converted to 5 spaces:
Page 7 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
$ newform -i file | od -c
0000000 r e d g r e e n \n
0000016
Now specify a tabspec argument with the -i option. Note that there
should be no space between -i and the value for tabspec.
$ newform -i-4 file
red green
Since newform assumes the presence of a tab stop in column 5 in this
case, the word green begins on column 5. The tab character is con-
verted to just one space.
Define a list of tab stops. To do this, you first create a file con-
taining several tabs in one line:
$ cat > file1
red <TAB> green <TAB> blue <TAB> yellow
<CTRL> <D>
$ newform -i5,13,18 file1
red green blue yellow
Here newform assumes tab stops in columns 5, 13, and 18. The word
green thus begins on column 5, i.e. the first tab is converted to one
space; the word "blue" begins on column 13, i.e. the second tab is
converted to 3 spaces, and so on.
Converting spaces to tabs: option -o
Example 2
The contents of file are:
red green
There are 5 spaces between the words red and green. Convert the spaces
to a tab:
$ newform -o file | od -c
0000000 r e d \t g r e e n \n
0000012
newform assumes a tab stop in column 9 and converts all spaces that
immediately precede column 9 to 1 tab character.
Page 8 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
Now enter a value of -6 for tabspec:
$ newform -o-6 file | od -c
0000000 r e d \t g r e e n \n
0000014
All spaces immediately preceding column 7 have been converted to 1 tab
character. This tab is followed by the remaining two spaces.
Truncating and extending lines
Example 3
The contents of file are:
monday
tuesday
wednesday
thursday
friday
saturday
sunday
All lines from file that are longer than 6 characters are to be trun-
cated to the right so that the effective line length equals 6 charac-
ters:
$ newform -l6 -e file
monday
tuesda
wednes
thursd
friday
saturd
sunday
All lines from file are to be output with right justification, ending
at column 20:
$ newform -l20 -p file
monday
tuesday
wednesday
thursday
friday
saturday
sunday
The following newform call deletes the sequence number area (columns
1-6) from a COBOL program:
Page 9 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
$ newform -l1 -b6 program
.
.
.
The -l1 option is required to ensure that every line is truncated by 6
characters (see Example 5).
Rearrange line segments: option -s
Example 4
The contents of file are:
Mason <TAB> Edward
Montana <TAB> Dave
$ cat file
Mason Edward
Montana Dave
You now want to rearrange the lines so that the last name follows the
first name with one intervening space.
$ newform -a1 -s file
Edward Mason
Dave Montana
First, the -a1 option appends one space to the end of the lines. The
-s option then shears off the surname and the tab character, and
appends the surname to the end of the line.
The same effect could also have been achieved by specifying newform -s
-a1 file. newform would have then sheared off the surnames and tabs
first, saved the surnames internally, appended a space to the end of
the line, and finally added the surnames as well (see Example 6).
Sequence of options/repeating options
Example 5
The contents of colors are:
red
violet
blue
magenta
Truncate two characters from the end of all lines that are longer than
4 characters:
Page 10 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
$ newform -l4 -e2 colors
red
viol
blue
magen
A different result is obtained if you switch the two options:
$ newform -e2 -l4 colors
red
violet
blue
magenta
In this case, the effective line length is first set to the default
value of 80, i.e. only lines that exceed 80 characters in length are
truncated. There are no such lines in the example. The effective line
length is then set to a value of 4; however, this is no longer signi-
ficant.
Now all the lines in colors which have no more than 5 characters are
to be prefixed with an asterisk. Then all lines that are longer than 6
characters are to have the last character cut off.
$ newform -l5 -c* -p1 -l6 -e1 colors
*red
violet
*blue
magent
Example 6
The contents of orders are:
1000 <TAB> Meyer <TAB> Frankfurt
150 <TAB> Miller <TAB> London
750 <TAB> Patel <TAB> Bombay
2500 <TAB> Smith <TAB> Perth <TAB> ***
The lines in the file are now to be reformatted as follows:
The numbers and initial tabs are to be truncated so that the names
come first. The remaining tabs are to be expanded into spaces, with
tab stops set every 15 columns (i.e. in columns 16, 31, 46, etc.). All
lines are then to be padded up to column 30 with spaces, or truncated
from column 31 onward as required. The previously sheared off numbers
are then to be appended to each line starting at column 31.
Page 11 Reliant UNIX 5.44 Printed 11/98
newform(1) newform(1)
This can be accomplished by calling newform as follows:
$ newform -s -i-15 -l30 -a -e orders
Meyer Frankfurt 1000
Miller London 150
Patel Bombay 750
Smith Perth 2500
Note that the options are processed from left to right. When the
numbers and tabs have been sheared off (option -s), the names begin on
column 1. Following the expansion of the remaining tabs to spaces
(option -i-15), only the first three lines are shorter than 30 charac-
ters and hence padded with spaces (option -a); the last line exceeds
30 characters in length and is therefore truncated at the end (option
-e). The initially sheared off numbers are finally appended to the end
of each relevant line (option -s, step 2).
SEE ALSO
csplit(1), tabs(1), fspec(4).
Page 12 Reliant UNIX 5.44 Printed 11/98