トップQs
タイムライン
チャット
視点

Nl (UNIX)

ウィキペディアから

Remove ads

nl は、ファイルまたは標準入力からの入力に行番号を添えて標準出力に出力する Unix コマンドである。

歴史

nl が登場したのは System V release 2 である[1]

このコマンドは 1987 年の第 2 版より X/Open Portability Guide の一部となっている。これは初版の POSIX.1Single Unix Specification に引き継がれた[2]

GNU coreutils に含まれている nl は Scott Bartram と David MacKenzie によって書かれたものである[3]

以下はファイル filename の行を表示する例と、ps コマンドの出力をパイプで渡す例である。

$ nl filename 
     1	hoge
     2	fuga
       
     3	piyo
     4	hogehoge
$ ps | nl
     1	    PID TTY          TIME CMD
     2	 930631 pts/1    00:00:00 bash
     3	2077186 pts/1    00:00:00 ps
     4	2077188 pts/1    00:00:00 nl

次に示す例は、文字 A から始まる行 (正規表現 /^A/ にマッチする行) のみを数え上げる。コマンド中の filename は省略可能である。

$ nl -b p^A filename
       apple
    1  Apple
       BANANA
    2  Allspice
       strawberry

以下のようにすると grep -n の代わりとして利用できる。

$ cat somefile
aaaa
bbbb
cccc
dddc
$ nl somefile | grep cccc
    3 cccc
Remove ads

関連項目

脚注・出典

Loading content...
Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads