![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
awk question..
Hi All,
I need to add up values given by the grep command.Following is the sample: Code:
[root@iqmango ~]# grep cores /proc/cpuinfo cpu cores : 4 cpu cores : 4 cpu cores : 4 cpu cores : 4 cpu cores : 4 cpu cores : 4 cpu cores : 4 cpu cores : 4 Thanks! nua7 |
|
||||
|
This won;t work , because I need to count the total number of cores , including all processors.
Code:
[root@iqmango ~]# grep cores /proc/cpuinfo |wc -l 8 Hope the confusion is clear. Thanks! nua7 |
|
||||
|
Actually, that's not going to give you the right number, because there is an entry in /proc/cpuinfo for each core. So if you have 2 4-core processors, even though there will be 8 entries in /proc/cpuinfo, each will report that their processor contains 4 cores, and you will get a result of 32 when in fact you only have 8 cores.
santysham's solution will actually give you the correct result, perhaps in a not very obvious way. You can abbreviate it to grep -c cores /proc/cpuinfo. |
|
||||
|
Sure, it works, but the result is wrong! ;-)
|
| Sponsored Links | ||
|
|