(動画教材準備中)
atama : head コマンドの代用
Usage : atama [-n] [-]<n> <file>
atama [-n] [-]<n>c <file>
Version : Wed Oct 22 20:46:41 JST 2014
標準入力からファイルを読む場合、head コマンドは先頭のデータを出力した後に直ちに終了しますが、atama コマンドは直ちには終了せず、残りの データも読み込みます。(読み捨てる)<file> が無指定あるいは "-" の時には、標準入力を読み込みます。
このため、パイプラインにおいて、
$ cat bigfile | head
$ cat bigfile | atama
としたとき、前者が cat コマンドがエラー終了する(head コマンドが終了してしまうので、cat コマンドの標準出力が "目詰まり" を起こす)のに対し、後者はエラーを起こしません。
-n オプションは付けても付けなくても同じ動作をします。
atama -n -5
atama -n 5
atama -5
atama 5
は同じ動作をします。
先頭3行を出力します。
$ cat file
a
b
c
d
e
$ atama -3 file > result
$ cat result
a
b
c
例2
先頭10文字を出力します。マルチバイト文字は考慮されず、文字数はバイト数でカウントされます。
$ cat file
abcdefghijklmnopqrstuvwxyz
$ atama -10c file > result
$ cat result
abcdefghij$ <--改行コードは無いため、プロンプトが出力直後に出る
複数ファイル指定には対応してません。
headと違い、オプションなしで実行した際には、usageを表示します。
$ seq 20 | head
1
2
3
4
5
6
7
8
9
10
$ seq 20 | atama
Usage : atama [-n] [-]<n> <file>
atama [-n] [-]<n>c <file>