How to you find read statistics for bam files with terminal mismatch?
Could you provide some examples of lines that should be counted? I'm not sure how mismatches are encoded in the version of Bowtie you're using. As far as I remember, Bowtie doesn't distinguish between = and X in CIGARs (and uses M for both), therefore, mismatches must be detected from the MD tag. 

You can use SAMsift for filtering the alignments. The following filtering criterion should keep only reads with  read length from 18 to 34 that have an MD tag with 0 as the last character, which must be preceded by a non-number (this should signalise a mismatch at the last position).

samsift \
  -i test1.bam \
  -f '18 &lt;= len(SEQ) &lt;= 34 and MD[-1]=="0" and not MD[-2].isdigit()' \
  -m nonstop-remove


The obtained alignments can be counted by adding | samtools view | wc -l.

Explanation:


-f ... – filtering criterion
18 &lt;= len(SEQ) &lt;= 34 – the allowed read lengths
MD[-1]=="0" – the last character of the MD tag is 0
not MD[-2].isdigit() – the penultimate character of the MD tag is not a digit
-m nonstop-remove – remove alignments without any MD tag (probably unaligned, they would cause an error).