Use of awk to filter out the command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of awk to filter out the command output
# 1  
Old 01-28-2014
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 :
PHP Code:
System Hardware
    Model
:              ia64 hp Integrity Virtual Partition
    Main Memory
:        6137 MB
    Processors
:         2
        Intel
(R)  Itanium(R)  Processor 9560 (2.53 GHz32 MB)
        
8 cores16 logical processors per socket
        6.38 GT
/s QPICPU 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
Code:
# 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
# 2  
Old 01-28-2014
Code:
print_manifest | awk '/core/ {print $1}'

# 3  
Old 01-28-2014
thanks a lot CarloM...i am able to filter out the number of cores using this option Smilie

---------- 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 :
Code:
 
# print_manifest | awk '/core/ { print $1 }'
8
1

i want to print the last line and i am doing it using command :
Code:
# 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 :

Code:
# 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 :
PHP Code:
logical processor count :16
logical processor count 
:
then using tail i can display the last line that is
PHP Code:
logical processor count :

thanks a lot again Smilie
# 4  
Old 01-28-2014
Try:
Code:
awk '/logical processors (.* per socket)/ {printf "Logical processors: %s\n", $1}'

# 5  
Old 01-28-2014
great , really very helpful Smilie

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
PHP Code:
16 logical processors
2 logical processors 
in your reply the search pattern is
/logical processors (.* per socket)/
can we make it as like :
PHP Code:
/<any numerical valuelogical 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
PHP Code:
/logical processors (.* per socket)/ 
thank you very much

# 6  
Old 01-28-2014
Code:
/[[: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
Code:
/[[:digit:]][[:digit:]]* logical processors/

.

But if you want both lines you can just match
Code:
/logical processors/

The per socket part was so it would get just the last one.
# 7  
Old 01-28-2014
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..Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

No output from awk command

Hi all, In my SunOS 5.10, the command awk using BEGIN option doesn't print output variables like expected here is my test: with the following code everything is alright ps -eo pcpu,args | grep "httpd" | awk ' { print $1 } ' the result is 0.1 However, with this command ps -eo... (3 Replies)
Discussion started by: Elmassimo
3 Replies

2. Shell Programming and Scripting

Grep output to awk command

Hi Team(Solaris 5.8/Ksh), How can we save grep output to awk variable when grep returns more than one line or word. abc.log # more abc.log Hi Makarand How r u bye Makarand Hello when grep returns only 1 word below command works nawk -v var=`cat abc.log |grep "Hello"` 'BEGIN { if... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

3. Shell Programming and Scripting

Filter output in curl

Hello guys, I'm writing a little script which sends me sms with my shell script via api of a sms provider. problem is I can't filter my curl output for this site: site url:... (1 Reply)
Discussion started by: genius90
1 Replies

4. Shell Programming and Scripting

Use of awk/sed to filter out fdisk output

Hi , I am trying to filter out the below output of fdisk -l command : fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 ... (9 Replies)
Discussion started by: omkar.jadhav
9 Replies

5. Shell Programming and Scripting

How the filter output?

Hey, I'm using some sensors that can be read by http. If I run following command: curl -v 'http://192.168.111.23:8080/sensor/52f5c63cc4221fbbedcb499908a0a823?version=1.0&interval=minute&unit=watt&callback=realtime' I'm getting: I would like to put this now in a sheet with only the... (9 Replies)
Discussion started by: brononius
9 Replies

6. Shell Programming and Scripting

Format output in AWK command

hi Friends , I have a file as below s.txt 1~2~~4 2~6~~7 3~8~~9 t.txt 1~2~~4 2~5~8~7 3~8~~7 header for both files is common (2 Replies)
Discussion started by: i150371485
2 Replies

7. Emergency UNIX and Linux Support

getting wrong output with AWK command!!!

i have a file which gets appended with 9 records daily and the file keeps growing from then...i use to store the previous day files count in a variable called oldfilecount and current files count as newfilecount.my requirement is that i need to start processing only the new records from the... (3 Replies)
Discussion started by: ganesh_248
3 Replies

8. IP Networking

Filter wireshark output

Hi I have a wireshark file saved (from my network) and I have to analyze the flows inside it. The problem is that i have to analyze not the complete file (60.000 pkts!) but just a subset of it. In other words i have to sample the wireshark.file.dump and for example from 60.000 pkts take... (2 Replies)
Discussion started by: Dedalus
2 Replies

9. Shell Programming and Scripting

Format Output with AWK command

Hi - I have a file with contents as below. 12.1 a.txt 12.1 b.txt 12.1 c.txt 13.2 a.txt 13.2 d.txt 14.3 f.txt 15.4 a.txt 15.4 b.txt 15.4 z.txt I need to print the contents like this. 12.1 a.txt <&nbsp><&nbsp><&nbsp>b.txt <&nbsp><&nbsp><&nbsp>c.txt (7 Replies)
Discussion started by: guruparan18
7 Replies

10. Shell Programming and Scripting

space in output from awk command

Hi I have tried this command cat /etc/passwd | awk -F: '{print$5}' note that the $5 is the column that displays full name- i.e. Kevin Kambell To the point, my output is fine except one thing I do not understand that some of output lines have space in front of them which I checked in... (7 Replies)
Discussion started by: lalelle
7 Replies
Login or Register to Ask a Question