I have aligned a file with BWA MEM but since the file is big (1 Tb) I could not sort it with samtools due to memory limits. I tried with sambamba but I got an error:
or use samtools. These days they are equally fast afaik.
By the way, samtools sort does not have a memory limit. It has an option -m that decides how much RAM is used to keep temporary data in memory before spilling them to disk as tmp files. You can sort your file with it. It is recommended though that you do not store SAM files due to the size. You can directly store as BAM having a notably reduced file size.
Thanks, I overlooked the conversion -- that's why the file was so large. Usually, I pipe everything including samtool sort. Is there a better tool to sort a large bam file?
No afaik, I think samtools and sambamba are as good as it gets. For large files it will take time though unless you have a lot of memory so you can keep larger chunks in RAM. But yes, piping is definitely desirable to avoid large intermediate files that you eventually are going to delete anyway.
the output of bwa-mem is an unsorted SAM file, not a BAM file.