You can print the output of lscpu in JSON format, then select what you need with jq:
[user@laptop ~]$ lscpu -J|jq .lscpu[0]
{
"field": "Architecture:",
"data": "x86_64"
}
[user@laptop ~]$
Or in CSV format:
[user@laptop ~]$ lscpu --parse --output-all
# The following is the parsable format, which can be fed to other
# programs. Each different item in every column has an unique ID
# starting usually from zero.
# BOGOMIPS,CPU,Core,Socket,Cluster,Node,Book,DRAWER,L1d:L1i:L2:L3,Polarization,Address,Configured,Online,Mhz,SCALMHZ%,Maxmhz,Minmhz
5188.21,0,0,0,,0,,,0:0:0:0,U,,,Y,1809.9220,57%,3200.0000,500.0000
5188.21,1,0,0,,0,,,0:0:0:0,U,,,Y,797.6560,25%,3200.0000,500.0000
5188.21,2,1,0,,0,,,1:1:1:0,U,,,Y,880.4450,28%,3200.0000,500.0000
5188.21,3,1,0,,0,,,1:1:1:0,U,,,Y,2095.2959,65%,3200.0000,500.0000
[user@laptop ~]$
Another aproach is to use ansible:
[user@laptop ~]$ ansible -i localhost, -m setup all|sed 's/localhost | SUCCESS => //'|jq .ansible_facts.ansible_processor
[
"0",
"GenuineIntel",
"Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz",
"1",
"GenuineIntel",
"Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz",
"2",
"GenuineIntel",
"Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz",
"3",
"GenuineIntel",
"Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz"
]
[user@laptop ~]$
3rd aproach would be to parse the info from /proc/cpuinfo
:
[user@laptop ~]$ grep 'model name' /proc/cpuinfo
model name : Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
model name : Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
model name : Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
model name : Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
[user@laptop ~]$