I have a large gzipped mysqldump file which contains some table definitions and then many insert statements. I'd like to edit the table definitions but leave the insert statements alone. The file is about 500gb when it's compressed so I'd like to avoid ungzipping it just to edit it. To skip the header I could do

zcat bigfile.gz | tail -n+50

And to just add the header to another gzipped file I can do

zcat header.gz bigfile.gz

But is there any way to combine these two statements?


You could use process substitution, which is more idiomatic and less cumbersome than a named pipe.

cat header.sql <(zcat bigfile.gz | tail -n+50)

I ended up using a named pipe to solve this problem and three shells (via tmux):


mkfifo pipe

Start shell 1:

cat header.sql > pipe

Then start shell 2:

zcat bigfile.gz | tail -n+50 > pipe

Then start shell 3

cat pipe | mysql -uroot -pxyz database_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.