Section Next | Prev


2.4.2 ファイルデータの結合・表示(cat)

【機能説明】
指定したファイルの内容を読み、標準出力に表示します。ファイル名を指定しない ときは、標準入力の内容を表示します。
cat は concatenate(連結) の意味だと言われています。

【入力フォーマット】
cat [オプション][ファイル ... ]

【主なオプション】
e (end of line)
行末をドル記号($)で表示します。
n (number)
各行の先頭に行番号をつけます。
s (silent)
エラーメッセージを表示しません。
v (view)
コントロールキャラクタを見える形で表示します。 例えば <CTRL/X> ならば、 ^X と表示します。
t (tab)
-v と同じ。但しタブ文字も ^I として表示

【実行例】
1.ファイルの連結表示
name.lis1 と name.lis2 の内容を cat コマンドを使って表示させます。
	[student@h006 ~]$ ls name.lis?
	name.lis1
	name.lis2

	[student@h006 ~]$ cat name.lis1
	Abe
	Osako
	Okada
	Kato

	[student@h006 ~]$ cat name.lis2
	Tanimura
	Nogami
	Shiina

2.ファイルの連結(リダイレクション)
ファイル name.lis1 と name.lis2 を入出力リダイレクション記号(>) を使ってファイル name.list に出力させます。
ファイル name.list の内容は、 name.lis1 と name.lis2 を結合したものになります。
	[student@h006 ~]$ cat name.lis1 name.lis2 > name.list
	[student@h006 ~]$ cat name.list
	Abe
	Osako
	Okada
	Kato
	Tanimura
	Nogami
	Shiina

3.標準入力の取込
標準(キーボード)入力をファイルに書き込むには、次のようにします。
	[student@h006 ~]$ cat > title
	*** name list ***
	^D
	[student@h006 ~]$

入力の最後には ^D (EOF:End Of File) を入力します。

追加出力リダイレクション記号(>>) を使って、ファイル name.list をファイル title に追加させる事もできます。

	[student@h006 ~]$ cat name.list >> title
	[student@h006 ~]$ cat title
	*** name list ***
	Abe
	Osako
	Okada
	Kato
	[student@h006 ~]$ 

4.ファイルと標準入力の連結
またファイル名にハイフン(−)を指定する事で標準入力を指定出来ます。
	[student@h006 ~]$ cat - name.lis1 - name.lis2 > name.lisx
	======== name.lis1 ========
	^D
	======== name.lis2 ========
	^D 
	[student@h006 ~]$ cat name.lisx
	======== name.lis1 ========
	Abe
	Osako
	Okada
	Kato
	======== name.lis2 ========
	Tanimura
	Nogami
	Shiina

さらに cat には圧縮されたファイルを展開しながら標準出力へコピーする、 zcat があります。

Section Next | Prev

Copyright 2007-2018 ycosSystems GettingStart/Body242.html