LoginSignup
27
12

More than 5 years have passed since last update.

gzip 圧縮したテキストファイルは cat でつなげても大丈夫だよ

Last updated at Posted at 2015-07-16

仕様

RFC 1952 にも書いてあるよ

A gzip file consists of a series of "members" (compressed data sets). The format of each member is specified in the following section. The members simply appear one after another in the file, with no additional information before, between, or after them.

gzip ファイルのフォーマットは単に member の連続でしかないとのこと。
なら member の連続どうしの gzip ファイルを 2 つ以上つなげても同じだよね。

実際にやってみよう

$ echo hello | gzip -c > hello.gz
$ echo world | gzip -c > world.gz
$ cat hello.gz world.gz > helloworld.gz
$ gzip -dc < helloworld.gz
出力結果
hello
world

OK

ところで

zcat について書かれたページ
http://itpro.nikkeibp.co.jp/article/COLUMN/20060228/231000/

gzipやcompressで圧縮されたファイル(拡張子.gz)の内容を表示する。catコマンドとは違い,複数の.gzファイルを圧縮されたまま連結することはできない。zcatに関連するコマンドとしては,zmore,zlessがある。動作はmoreおよびlessと似ている。

この文を読むだけでは cat では繋げられないと勘違いしてしまいそう ><
もちろん zcat が必要なケース・あると便利なケースがあることを筆者は否定しないよー。

バージョン情報

念のためバージョン情報を。 gzip --version で出した。
GNU 系と BSD 系で試したかったので、
手元の OS X と Ubuntu (Linux) の gzip で試した。

BSD GZIP

Apple gzip 242

GNU GZIP

gzip 1.6
Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
Copyright (C) 1993 Jean-loup Gailly.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.

免責

この情報はいかなる種類の保証も伴わずに「現状のまま」で提供するよ。
筆者はいろいろと責任を負わないし負えないよ。 (ry

27
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
12