Home > database >  Gzip and rename issue
Gzip and rename issue

Time:07-22

I'm trying to decompress a gz file and rename it. The issue is that the file has size 0 after doing it:

var1="imdb"
var2="gz"
var3="tsv"
gzip -d --no-name "/tmp/${var1}.${var2}" > "tmp/${var1}.${var3}

After this I check ls -l /tmp and get the following

777642064 imdb
0         imdb.tsv

I tried the same with the following, it works but then it uses a random name:

gzip -d --name "/tmp/${var1}.${var2}"

777642064   randoname.tsv

CodePudding user response:

One option is to force gzip to write the decompressed data to stdout (-c) and then redirect stdout to the desired file, eg:

gzip -d -c "/tmp/${var1}.${var2}" > "/tmp/${var1}.${var3}"

NOTE: this will leave the original zipped (.gz) file in place

  • Related