昨日のシェル芸ヴェンキョウカイ(問5)で話題(?)になった、nlコマンドのオプションについて。これもさらりとオプションの再確認だけ……
と思っていたのですが、『論理ページ』なるものが気になったのでむしろそちらをメインに確認してきます。
論理ページのセクションの区切り文字について
- \:\:\: … ヘッダ
- \:\: … 本文
- \; … フッタ
テストデータ
今回は論理ページの区切りを仕込んだ手作成のデータを使用します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
% 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
17
18
|
% 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
|
ヘッダとフッタには番号が振られず、また、本文はセクションごとに番号が振りなおされています。
また、セクションの区切り文字は表示されていません。なるほど、nlってこういうことをするためのコマンドだったのね・・・
行番号を付けたり消したりするオプション
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% 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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% 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
|
% 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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% 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
|
% 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
|
※ヘッダとフッタに連続で採番し、本文には採番しない
行番号の採番方法を変える
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% 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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% 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
|
行番号の表示方法を変更
- -n format
- ln 左詰め
- rn 右詰め
- rz 右詰め(左0あり)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% 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
|
- -s 文字 行番号とテキストの間の区切り文字を指定。初期値はtab。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% 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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
% 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
|
「-d」オプションだけは試してみたけどよくわからなかった……
参考URL