I have around 500 GB free disk space on my SSD. I'm trying to run an operation on 10 gzipped files (each around 25GB in size). But I keep running out of storage when I do it in a parallel
for loop since sort
writes a lot of temporary files
in the same directory and apparently doesn't clean up after itself.
I'm trying to randomly take a certain number of lines from these files.
bcftools view "${FILES[i]}".vcf.gz | awk '{printf("%f\t%s\n",rand(),$0);}' | sort -t $'\t' -T . -k1,1g | head -n "${SUBSET_COUNT[i]}" | cut -f 2- >> "${FILES[i]}"_"${SUBSET_COUNT[i]}"_subset.vcf &
This operation takes around 1 hour on each file (when I do it one by one), but I want to do it in parallel, since I need to repeat this on more batches of such files.
#
)? Why do you need to sort? What is${SUBSET_COUNT[i]}
and where is it set?shuf
is inefficient especially for large files, that is why I avoidedshuf
. Yes, I'm already excluding the headers in my original for loop, here just for the sake of simplicity I kept the command to a bare minimum.