Obtaining number of functional groups in a compound from SMILES, SDF or MOL2 format

I'm looking for a tool that can give how many methyl groups, hydroxyl groups etc are in a compound's structure presented as SMILES, SDF or MOL2 format.

• obgrep -c '[CX3]' file.sdf # count the number of methyl groups
• obgrep -c '[#6][OX2H]' file.sdf # count the number of hydroxyl groups
• Thanks a lot. For testing I've used this file, it contains two methyl groups but the command: obgrep -c '[CX3]' HMDB37025.sdf  returning 0! May 5 '17 at 18:50