Fetching the required data out of a tabular form


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fetching the required data out of a tabular form
# 1  
Old 05-23-2016
Hammer & Screwdriver Fetching the required data out of a tabular form

Hello Gurus,

I am trying to fetch a required number of lines from an output of a command which is in tabular form.

Below is the command for reference along with how the result is being shown on UNIX shell.

Code:
/usr/openv/volmgr/bin/vmquery -b -p 5

The result of the above command is as below.

Code:
media   media  robot  robot  robot  side/  optical  # mounts/      last
 ID     type   type     #    slot   face   partner  cleanings    mount time
A01202  HCART  TLD      0     257     -       -          15     03/27/2016 07:29
A01262  HCART  TLD      0     361     -       -          31     05/20/2016 13:02
A01282  HCART  TLD      0      51     -       -          34     05/20/2016 15:21
KM3440  HCART  TLD      1      62     -       -         492     05/12/2016 00:55
KM3443  HCART  NONE     -      -     -       -         306     03/14/2014 16:37
KM3458  HCART  TLD      1     109     -       -         362     05/12/2016 05:40
KM3468  HCART  NONE     -      -     -       -           2     06/25/2015 15:21
KM3509  HCART  NONE     -      -     -       -          87     09/09/2014 06:01
LJY535  HCART  TLD      1     180     -       -         197     05/12/2016 11:48

If you see at the output closely, there is a column name "robot#" with values as [0,1,-]. All I want to do is to grep all rows with "robot# 0" and get the total count for it with "wc -l".

Kindly help.

Regards

Last edited by Don Cragun; 05-23-2016 at 05:11 AM.. Reason: Change QUOTE tags to CODE tags.
# 2  
Old 05-23-2016
It seems like:
Code:
/usr/openv/volmgr/bin/vmquery -b -p 5 | awk '$4==0{c++}END{print c}'

should give you what you want.

If you are running this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 05-23-2016
Hello Ali Sarwar,

Could you please try following and let me know if this helps you.
Code:
/usr/openv/volmgr/bin/vmquery -b -p 5 | awk '{n+=gsub(/^0$/,X,$4)} END{print n}'

I hope this helps.

Thanks,
R. Singh
# 4  
Old 05-23-2016
Hello Ravinder & DON,

Don's command is exactly what I was looking for. Would appreciate if this can be explained a bit further that What C++ is used for ? Why $4==0 what does END being used for ? Thanks you.


Code:
/usr/openv/volmgr/bin/vmquery -b -p 5 | awk '$4==0{c++}END{print c}'

Regards,
A.S
# 5  
Old 05-23-2016
Hello Ali Sarwar,

Following may help you in same.
Code:
awk '$4==0      ##### It is a condition check(similar what we do in if else condition check). Where $4 means 4th field and we are checking here if 4th field is 0 or not.
{
c++             ##### If 4th field is having ZERO value then there is variable named C, so we are incrementing it's value by doing c++ to one.
}
END{            ##### Here starts END block, in awk there are 3 sections, i- BEGIN- if you want to perform some operations in very starting of your program. ii- Body- where we write actual logic/code for our requirements. iii- END- block code will be executed when all Inputs are read from Input_file. 
print c}'       ##### printing the value of variable c, which will tell us how many 4th fields have value 0 in them.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 6  
Old 05-23-2016
That is great. Thank you very much. I miss-understood C++ with the tool C++.. So its just that I can use any variable to put in the value and increment it till I find my results.

Worked perfectly how I needed it. Thank you both. I will now close this thread.

Regards,
A.s

---------- Post updated at 03:18 PM ---------- Previous update was at 03:10 PM ----------

Solved
# 7  
Old 05-23-2016
Quote:
Originally Posted by Ali Sarwar
That is great. Thank you very much. I miss-understood C++ with the tool C++.. So its just that I can use any variable to put in the value and increment it till I find my results.

Worked perfectly how I needed it. Thank you both. I will now close this thread.
Regards,
A.s
---------- Post updated at 03:18 PM ---------- Previous update was at 03:10 PM ----------
Solved
Your Welcome Ali, for making threads solved. You should navigate to right most up corner of the page and click on EDIT TAGS and add solve there, in order to make a thread as solved. I will do it for you on this thread, you could explore that option though.

Thanks,
R. Singh

Last edited by RavinderSingh13; 05-23-2016 at 07:31 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Required to get out put of log in tabular format in email body

Dears Please support I have out put in text file and look like below fixed inquiries - Click on MAX suffix http://server:port/app User Details http://server:port/app Audit User Detail Action hhttp://server:port/app fixed inquiries - Click on MAX suffix http://server:port/app User Details ... (13 Replies)
Discussion started by: mirwasim
13 Replies

2. Shell Programming and Scripting

Dispaying output in tabular form

hi, I have a script which is dispaying the output as below: Column 3:value1 Column 4:value 4 column 8:value 8 column 9:value 9 column 13:value 13 Column 3:value10 Column 4:value 40 column 8:value 80 column 9:value 90 column 13:value 103 However,I need the output in tabular... (5 Replies)
Discussion started by: Vivekit82
5 Replies

3. Shell Programming and Scripting

Displaying log file pattern output in tabular form output

Hi All, I have result log file which looks like this (below): from the content need to consolidate the result and put it in tabular form 1). Intercomponents Checking Passed: All Server are passed. ====================================================================== 2). OS version Checking... (9 Replies)
Discussion started by: Optimus81
9 Replies

4. Shell Programming and Scripting

Generate tabular data based on a column value from an existing data file

Hi, I have a data file with : 01/28/2012,1,1,98995 01/28/2012,1,2,7195 01/29/2012,1,1,98995 01/29/2012,1,2,7195 01/30/2012,1,1,98896 01/30/2012,1,2,7083 01/31/2012,1,1,98896 01/31/2012,1,2,7083 02/01/2012,1,1,98896 02/01/2012,1,2,7083 02/02/2012,1,1,98899 02/02/2012,1,2,7083 I... (1 Reply)
Discussion started by: himanish
1 Replies

5. UNIX for Dummies Questions & Answers

Put data in tabular form..

Dear Friends, I have a file as under : +++ ME 12-06-13 18:16:20 A RED FEW AND ROW1 1MN FEL AS HI FI BV LR TS HR ES MR * 0 13296 0 120 1 15 KS RR 10 0 +++ ME 12-06-13 18:26:20 A RED FEW AND ROW2 1MN FEL AS... (2 Replies)
Discussion started by: vanand420
2 Replies

6. UNIX for Dummies Questions & Answers

Put data into tabular form

Hi I am having a file which is required to be presented in the under-noted output form. Please suggest. Input: Kapil: apple 4 banana 6 cherry 0 Manoj: apple 13 banana cheery 2 Output: apple banana cherry Kapil: 4 6 0 Manoj: 13 2 Thanks in... (4 Replies)
Discussion started by: vanand420
4 Replies

7. Shell Programming and Scripting

Tabular form in shell script

hi, I need to mention the data in tabular form in shell script. :confused: Input as below: Health check (heading1) CPU/Memory Utilization of pc on server (h2) 1214 of rpc3 is exceeds 0.3 % (data) CPU Utilization is normal for rpc/33 on 2673 CPU Utilization is normal for rpc/33 on... (2 Replies)
Discussion started by: sreelu
2 Replies

8. UNIX and Linux Applications

Get the data in my required form using gawk

i had the data in the following form: Branch : 3379 As On : 31-JAN-2009 Page : 1 User Id : OPER1 Date & Time : 01-FEB-2009 04:02:37 ... (2 Replies)
Discussion started by: KANNI786
2 Replies

9. UNIX for Dummies Questions & Answers

How to read tabular data?

Hello, I have a log file which contains data in tabular format(3 columns(total, posted, rejected) and 2 rows(close, total)) as below. TOTAL POSTED REJECTED CLOSE 3 3 0 TOTAL 3 3 0 I have to search for all Total... (1 Reply)
Discussion started by: akash028
1 Replies

10. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies
Login or Register to Ask a Question