昨日のシェル芸ヴェンキョウカイ(問5)で話題(?)になった、nlコマンドのオプションについて。これもさらりとオプションの再確認だけ……
と思っていたのですが、『論理ページ』なるものが気になったのでむしろそちらをメインに確認してきます。

### 論理ページのセクションの区切り文字について
  • \:\:\: … ヘッダ
  • \:\: … 本文
  • \; … フッタ
### テストデータ 今回は論理ページの区切りを仕込んだ手作成のデータを使用します。 ```sh % cat nldata \:\:\: this is header line 1 this is header line 2 \:\: this is main section.

aaaaa bbbbb

after 1 blank cccc :: this is second main section. ddddd

after 2 blank eeeeeeee fffffff gggg : this is footer line 1 this is footer line 2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16

<ul>
<li>ヘッダ…2行</li>
<li>本文1…6行</li>
<li>本文2…7行</li>
</ul>という構成になっています。<br/>
<br/>


</div>
<div class="section">
    ### オプションの確認
    
<div class="section">
    #### オプションなし
    まずは、オプションなしで実行してみます。

% nl nldata this is header line 1 this is header line 2 1 this is main section.

 2  aaaaa
 3  bbbbb

 4  after 1 blank cccc
 1  this is second main section.
 2  ddddd


 3  after 2 blank eeeeeeee
 4  fffffff
 5  gggg
    this is footer line 1
    this is footer line 2
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
また、セクションの区切り文字は表示されていません。なるほど、nlってこういうことをするためのコマンドだったのね・・・<br/>
<br/>


</div>
<div class="section">
    #### 行番号を付けたり消したりするオプション
    
<ul>
<li>-b a 「本文の」行全部に行番号をつける</li>
</ul>```sh
% nl -b a nldata
        this is header line 1
        this is header line 2
     1  this is main section.
     2
     3  aaaaa
     4  bbbbb
     5
     6  after 1 blank cccc
     1  this is second main section.
     2  ddddd
     3
     4
     5  after 2 blank eeeeeeee
     6  fffffff
     7  gggg
        this is footer line 1
        this is footer line 2

  • -h a 「ヘッダの」行全部に行番号をつける
```sh % nl -h a nldata 1 this is header line 1 2 this is header line 2 1 this is main section.
 2  aaaaa
 3  bbbbb

 4  after 1 blank cccc
 1  this is second main section.
 2  ddddd


 3  after 2 blank eeeeeeee
 4  fffffff
 5  gggg
    this is footer line 1
    this is footer line 2
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<ul>
<li>-f a 「フッタの」行全部に行番号をつける</li>
</ul>```sh
% nl -f a nldata
        this is header line 1
        this is header line 2
     1  this is main section.

     2  aaaaa
     3  bbbbb

     4  after 1 blank cccc
     1  this is second main section.
     2  ddddd


     3  after 2 blank eeeeeeee
     4  fffffff
     5  gggg
     1  this is footer line 1
     2  this is footer line 2

  • -p セクションを超えても連番を保持する
```sh % nl -p nldata this is header line 1 this is header line 2 1 this is main section.
 2  aaaaa
 3  bbbbb

 4  after 1 blank cccc
 5  this is second main section.
 6  ddddd


 7  after 2 blank eeeeeeee
 8  fffffff
 9  gggg
    this is footer line 1
    this is footer line 2
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
% nl -p -h a -b n -f a nldata
     1  this is header line 1
     2  this is header line 2
        this is main section.

        aaaaa
        bbbbb

        after 1 blank cccc
        this is second main section.
        ddddd


        after 2 blank eeeeeeee
        fffffff
        gggg
     3  this is footer line 1
     4  this is footer line 2

```※ヘッダとフッタに連続で採番し、本文には採番しない<br/>
<br/>


</div>
<div class="section">
    #### 行番号の採番方法を変える
    
<ul>
<li>-i num 行番号の増分値を指定</li>
</ul>```sh
% nl -i 2 nldata
        this is header line 1
        this is header line 2
     1  this is main section.

     3  aaaaa
     5  bbbbb

     7  after 1 blank cccc
     1  this is second main section.
     3  ddddd


     5  after 2 blank eeeeeeee
     7  fffffff
     9  gggg
        this is footer line 1
        this is footer line 2

```
<ul>
<li>-v num 行番号の初期値を指定</li>
</ul>```sh
% nl -v 25 nldata
        this is header line 1
        this is header line 2
    25  this is main section.

    26  aaaaa
    27  bbbbb

    28  after 1 blank cccc
    25  this is second main section.
    26  ddddd


    27  after 2 blank eeeeeeee
    28  fffffff
    29  gggg
        this is footer line 1
        this is footer line 2

```
</div>
<div class="section">
    #### 行番号の表示方法を変更
    
<ul>
<li>-n format
<ul>
<li>ln 左詰め</li>
<li>rn 右詰め</li>
<li>rz 右詰め(左0あり)</li>
</ul></li>
</ul>```sh
% nl -n rz nldata
        this is header line 1
        this is header line 2
000001  this is main section.

000002  aaaaa
000003  bbbbb

000004  after 1 blank cccc
000001  this is second main section.
000002  ddddd


000003  after 2 blank eeeeeeee
000004  fffffff
000005  gggg
        this is footer line 1
        this is footer line 2

```
<ul>
<li>-s 文字 行番号とテキストの間の区切り文字を指定。初期値はtab。</li>
</ul>```sh
% nl -s , nldata
      ,this is header line 1
      ,this is header line 2
     1,this is main section.
      ,
     2,aaaaa
     3,bbbbb
      ,
     4,after 1 blank cccc
     1,this is second main section.
     2,ddddd
      ,
      ,
     3,after 2 blank eeeeeeee
     4,fffffff
     5,gggg
      ,this is footer line 1
      ,this is footer line 2

```
<ul>
<li>-w num 行番号エリアの幅を指定。</li>
</ul>```sh
% nl -w 3 -s : -n rz nldata
   :this is header line 1
   :this is header line 2
001:this is main section.
   :
002:aaaaa
003:bbbbb
   :
004:after 1 blank cccc
001:this is second main section.
002:ddddd
   :
   :
003:after 2 blank eeeeeeee
004:fffffff
005:gggg
   :this is footer line 1
   :this is footer line 2

```<br/>
「-d」オプションだけは試してみたけどよくわからなかった……<br/>
<br/>


</div>
</div>
<div class="section">
    ### 参考URL
    
<ul>
<li><a href="http://kaworu.jpn.org/doc/FreeBSD/jman/man1/nl.1.php">nl(1) FreeBSDドキュメントJMan</a></li>
</ul>
</div>