This is a use case for replacing a process. Let's say you have two files to sort, sorta.gz and sortb.gz . You can give gunzip -c FILE.gz for sorting for both of these files using the shell operator <(...) :
sort -m -k1 <(gunzip -c sorta.gz) <(gunzip -c sortb.gz) >sorted
Process substitution replaces a command with a file name that represents the result of this command, and is usually implemented either with a named pipe or with a special file /dev/fd/...
For 40 files, you will need to dynamically create a command using many process substitutions and use eval to execute it:
cmd="sort -m -k1 " for input in file1.gz file2.gz file3.gz ...; do cmd="$cmd <(gunzip -c '$input')" done eval "$cmd" >sorted
source share