I want to use the number of cores in a script and I am not sure what is the best approach to extract the number itself.
For example, the below extracts the number of physical cores, however how should the actual number be extracted so that it can be used as an input elsewhere?
lscpu | grep "Core(s) per socket" Core(s) per socket: 4
I am aware of tail -c N, however I am worried about the fragility of this approach when working on machines with more cores.
What is the best approach to reliably get the number of physical cores and threads per core for use as input an parameter elsewhere?