1

Why does this give such output (both commands are supposed to do the same thing) and how can one make them give identical output?

diff <(cat some_file | gzip -c - | base64) <(gzip -c some_file | base64)
1,2c1,2
< H4sIACSOZFUAA2XNsRHAMAgDwDqZRkIQ8P6L+c5xnIL2m2c5E6BdIQA5cHPTaGTqlI3ki2jSoWrk
< e1Tw0PNSMT4KdPKfJgNiJT++AAAA
---
> H4sICGcqSlUAA2Z0X2FkLnNob3J0AGXNsRHAMAgDwDqZRkIQ8P6L+c5xnIL2m2c5E6BdIQA5cHPT
> aGTqlI3ki2jSoWrke1Tw0PNSMT4KdPKfJgNiJT++AAAA

The contents of the file are:

184170012   53000790
184170019   53000790
184170023   53000790
184170027   53000790
184170034   53001233
184170038   53001233
184170042   53000351
184170046   53000815
184170050   53000815
184170054   53000815

There is a tab character between two columns and new line at the end of each line.

1 Answer 1

2

gzip is encoding the filename of the input file into its output. Even with -c option it does this. You can see this with gzip -c some_file | strings|head -1. however, when reading from stdin, gzip does not do that, since it doesn't know the filename. You can tell gzip to omit from output the filename and time-stamp with -n.

5
  • closer but not quite there yet ) diff <(cat ft_ad.short | gzip -c - | base64) <(gzip -c -n ft_ad.short | base64) 1c1 < H4sIANiRZFUAA2XNsRHAMAgDwDqZRkIQ8P6L+c5xnIL2m2c5E6BdIQA5cHPTaGTqlI3ki2jSoWrk --- > H4sIAAAAAAAAA2XNsRHAMAgDwDqZRkIQ8P6L+c5xnIL2m2c5E6BdIQA5cHPTaGTqlI3ki2jSoWrk
    – iggy
    May 26, 2015 at 15:32
  • 2
    The gz also contains the modification time of the original file, if known, zero bytes if not. This is not prevented when using -n. See RFC 1952 for details on the file format.
    – Dubu
    May 26, 2015 at 15:35
  • To get two identical outputs, you need to use -n with both gzip commands. May 26, 2015 at 15:36
  • @Dubu -n tells gzip not to save the file name and time stamp (see linux.die.net/man/1/gzip for details). May 26, 2015 at 15:38
  • 1
    @Dubu, putting -n in both commands works, thanks
    – iggy
    May 26, 2015 at 15:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .