The numbers in this listing start at one and rise in increments of one.
Cobol usually operates in increments of 10 or 100, although one is valid.
Cobol numbering also includes leading zeroes, which this listing doesn't
display. Blank lines should be numbered but aren't. Finally,
default behavior is to add a tab separator after the
number and before the original line. Though the tabs are not visible in this
listing, many Cobol compilers can't handle them at all.
hello.cbl type hello.cbl 1 IDENTIFICATION DIVISION. 2 PROGRAM-ID. HELLO. 3 ENVIRONMENT DIVISION. 4 DATA DIVISION. 5 PROCEDURE DIVISION. 6 PROGRAM-BEGIN. 7 DISPLAY "Hello world." 8 PROGRAM-DONE. 9 STOP RUN.
Let's tackle these problems one at a time. The separator character
can be specified as an ordinary space using the
-s switch (as in
-s" "). The first modified version of the command is shown below.
$ nl -s" "
The format for the number itself is controlled by several options. The
option specifies the width of the number. For Cobol, this width is six.
The default for
nl happens to be six, but I'll include the option to be thorough. The
-v option lets you specify the starting number, and
you specify the increment. In the listing below, I've
specified a space separator, and a width of 6 digits, starting at 100 and
going up in increments of 100.
$ nl -s" " -w6 -v100 -i100
hello.cbl type hello.cbl 100 IDENTIFICATION DIVISION. 200 PROGRAM-ID. HELLO. 300 ENVIRONMENT DIVISION. 400 DATA DIVISION. 500 PROCEDURE DIVISION. 600 PROGRAM-BEGIN. 700 DISPLAY "Hello world." 800 PROGRAM-DONE. 900 STOP RUN.
This is closer, but it still needs work. The number format is controlled by the
-n option. There are three formats. Left-justified with leading zeroes suppressed is represented as
-nln. Right justified with leading zeroes suppressed is
-nrn. (This is the default.) Right-justified with leading zeroes kept is
-nrz. I use
-nrz in the following