JP1/Advanced Shell
形式
head[-行数|-n 行数][パス名 ...]
機能
ファイルの最初の数行を表示します。ファイルの最初の部分からそれぞれ指定した行数を標準出力に出力します。ファイルの指定がない場合,標準入力から入力します。行数を省略した場合は,10行を仮定します。
引数
- -行数 | -n 行数 〜<10進数>((1〜2147483647))
- 標準出力へ出力する,入力ファイルの最初の行数をそれぞれ指定します。0以下または2147483647より大きい値を指定すると,エラーメッセージ(head: line count too small: 指定値/head: line count too large: 指定値)を出力します。
- パス名
- 入力ファイル名を指定します。
- 省略時は標準入力から入力します。
- 複数ファイルを指定できます。複数ファイルを指定した場合,それぞれのファイルを識別するために,次に示す文字をそれぞれのファイルの出力に先行して出力します。2つ目以降のファイルの場合,改行のあとに次に示す文字を出力します。
==> ファイル名 <==
- 複数ファイルを指定して実行した場合,すべてのファイルに対して処理を行ってから,オープンに失敗したファイルが1つでもあると戻り値1で終了します。
戻り値
戻り値 意味 0 正常終了 1以上 エラー終了
使用例
headコマンドを実行した結果表示に使用するファイルの形式を次に示します。
- test1.txt
0001:test1.txt 0002:test1.txt 0003:test1.txt 0004:test1.txt 0005:test1.txt 0006:test1.txt 0007:test1.txt 0008:test1.txt 0009:test1.txt 0010:test1.txt- test2.txt
0001:test2.txt 0002:test2.txt 0003:test2.txt 0004:test2.txt 0005:test2.txt 0006:test2.txt 0007:test2.txt 0008:test2.txt 0009:test2.txt 0010:test2.txt
- test1.txtおよびtest2.txtファイルの最初の2行を表示します。
$ head -2 test1.txt test2.txt ==> test1.txt <== 0001:test1.txt 0002:test1.txt ==> test2.txt <== 0001:test2.txt 0002:test2.txt $- オプションエラーのメッセージを表示します。
- Windowsの例
このメッセージは,コマンドを実行するプラットフォームによって異なる場合があります。
C:\TEMP>%ADSH_OSCMD_DIR%\head -d head: illegal option -- d usage: head [-count | -n count] [file ...]
All Rights Reserved. Copyright (C) 2011, 2012, Hitachi, Ltd.