Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6009991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:03:06+00:00 2026-05-23T02:03:06+00:00

I have some sorted, gzipped files in a directory. How do I combine some

  • 0

I have some sorted, gzipped files in a directory. How do I combine some of them into another sorted, gzipped file? Right now I’m using explicit fifos. Is there a way to do it in bash without? I’m a bit of a bash noob, so please excuse my lack of style.

#!/bin/bash
# Invocation ./merge [files ... ]
# Turns an arbitrary set of sorted, gzipped files into a single sorted, gzipped file,
# printed to stdout. Redirect this script's output!
for f in $@
do
    mkfifo $f.raw
    gzcat $f > $f.raw &
    # sort -C $f.raw
done
sort -mu *.raw | gzip -c # prints to stdout.
rm -f *.raw

I’m looking to convert this into something like…

sort -mu <(gzcat $1) <(gzcat $2) <(gzcat $3) ... | gzip -9c # prints to stdout.

…but don’t know how. Do I need a loop building the parameters to string? Is there some sort of magic shortcut for this? Maybe map gzcat $@?

NOTE: Each of the files is in excess of 10GB (and 100GB unzipped). I have a 2TB drive, so this isn’t really a problem. Also, this program MUST run in O(n) or it becomes unfeasible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:03:07+00:00Added an answer on May 23, 2026 at 2:03 am

    You can combine eval and ‘process substitution’ with Bash. Assuming the basic file names don’t contain spaces (which, given that you use $@ instead of "$@" is probably the case), then something like:

    cmd="sort -mu"
    for file in "$@"
    do cmd="$cmd <(gzip -cd $file)"
    done
    eval $cmd | gzip -c9 > outputfile.gz
    

    You can also use bash -c "$cmd" instead of eval $cmd on the last line. If there are spaces in the file names, you have to work a bit harder. This works if the names don’t contain single quotes:

    cmd="sort -mu"
    for file in "$@"
    do cmd="$cmd <(gzip -cd '$file')"
    done
    eval $cmd | gzip -c9 > outputfile.gz
    

    With single quotes in the file names too, you have to work a lot harder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have potentially large files that need to be sorted by 1-n keys. Some
I have some objects in an array and want to have them sorted. The
I have some files that should be sorted according to id at the beginning
We have some files on our website that users of our software can download.
I have some data that is stored in a sorted vector. This vector is
I have some* experience using the flex framework for building web apps. But I
I have some very large (>4 GB) files containing (millions of) fixed-length binary records.
You are given two sorted integer arrays, which have some common integers. Any common
I have one DB table called table1 have some columns two of them are
I have some street numbers stored as VARCHARs but I want to sort them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.