Jonathan Jonathan - 7 months ago 38
Linux Question

How to pull only the value from lscpu in Linux?

If i want to get the CPU Mhz I use.

lscpu | grep "CPU MHz"
# CPU MHz: 1200.031

I only want to keep the 1200.031, how would I filter the CPU MHz: in the terminal?


To remove the leading whitespace leaving only the MHz value, you can do:

lscpu | sed -n 's/CPU MHz:[ \t]*//p'