Use of awk to filter out the command output

Hi All,

I am trying to find out number of cores present for hp-ux server from the output of print_manifest (as shown below). i suppose awk will be best tool to use for filtering.
output of print_manifest is :

 
System Hardware
    Model:              ia64 hp Integrity Virtual Partition
    Main Memory:        6137 MB
    Processors:         2
        Intel(R)  Itanium(R)  Processor 9560 (2.53 GHz, 32 MB)
        8 cores, 16 logical processors per socket
        6.38 GT/s QPI, CPU version D0
               Active processor count:
               1 socket
               1 core
               2 logical processors (2 per socket)
               LCPU attribute is enabled

search should satisfy below conditions :

  1. first it should check for presence of 'core' , this can be achived using
# print_manifest | grep -i "core"
        8 cores, 16 logical processors per socket
               1 core

now as the output shows , 8 cores are of physical machine on which this particular vm is built and 1 core is the actual number of cores assigned to this HP-UX vm. so can someone let me know how can i filter out only the numerical value that is 8 and 1

print_manifest | awk '/core/ {print $1}'

thanks a lot CarloM...i am able to filter out the number of cores using this option :slight_smile:

---------- Post updated at 07:46 AM ---------- Previous update was at 07:30 AM ----------

could you please aslo help me in getting the below output as u mentioned
print_manifest | awk '/core/ { print $1 }' gives two line output in my case output is like :

 
# print_manifest | awk '/core/ { print $1 }'
8
1

i want to print the last line and i am doing it using command :

# print_manifest | awk '/core/ { print $1 }' | tail -1
1

now i want to add few comments as in "number of cores:"
could you please let me know how can this be done.

also i am trying to filter out simillar thing for logical processors :

# print_manifest | awk '/logical processors/'
        8 cores, 16 logical processors per socket
               2 logical processors (2 per socket)

could you suggest some tricks using awk in order to filter out only the digits out of the above mentioned output ..for eg :
output should be :

 
logical processor count :16
logical processor count :2

then using tail i can display the last line that is

 
logical processor count :2

thanks a lot again :slight_smile:

Try:

awk '/logical processors (.* per socket)/ {printf "Logical processors: %s\n", $1}'

great , really very helpful :slight_smile:

just one more thing can i have a start pattern as any numerical value and then stop pattern as string for eg :
can i search for start and stop pattern which will give me output as

 
16 logical processors
2 logical processors 

in your reply the search pattern is
/logical processors (.* per socket)/
can we make it as like :

 
/<any numerical value> logical processors /
or 
/<any numerical value>/ /logical processors/

this will help me to make this command more generalised as in my case it may happen that on few servers we may not get below pattern

 
/logical processors (.* per socket)/ 

thank you very much

/[[:digit:]]+ logical processors/

should match for one or more leading digits. If that doesn't work it may be your awk doesn't support + , in which case try

/[[:digit:]][[:digit:]]* logical processors/

.

But if you want both lines you can just match

/logical processors/

The per socket part was so it would get just the last one.

yes CarloM i got it.

but what i mean to say was , the result of pattern matching search should be (irrespective of "per socket" word):

16 logical processors
2 logical processors

i am looking for awk output in the above format but search option should not contain "per socket" word

Coulld you pleas eguide me in searching abd displaying only the above pattern using awk or even sed..:slight_smile: