Sam files cannot have any trailing tabs at the end of each sam file entry. If you do, the sam-to-bam conversion (samtools view -Sb file.sam > file.bam) will not work.

This has actually been documented here:

I was able to get around this however, with a simple sed command:

sed 's/[ \t]*$//' file.sam > file.notrailingtabs.sam

Now, the sam-to-bam conversion will work:

samtools view -Sb file.notrailingtabs.sam > file.notrailingtabs.bam