![]() |
|
|
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 I can do this using a for loop , but wanted to know if this could be done in one line to make the code elegant, maybe using awk or some other tool. 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 This gives me the total number of processors but not cores.For cores I need to add up the lines as mentioned in the fiorst post. 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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|