Depending on your flavor of Linux you will get different results from /proc/cpuid.
This works for me on CentOS for getting total number of cores.
cat /proc/cpuinfo | grep -w cores | sed -e 's/\t//g' | awk '{print $3}' | xargs | sed -e 's/\ /+/g' | bc
The same doesn't work in Ubuntu. For Ubuntu you can use the following command.
nproc