Grep issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep issue
# 1  
Old 07-21-2014
Grep issue

HI,

I have a command to check a license file.
License_print.

In that file you get the headlines and all different licenses.

Now i want to have things extracted from it.
so i do like following:
Code:
license_print | grep -iw -e "user" -e "admin"

But i donīt want all lines where user is included and the same with admin.
The file looks like this:
Code:
 
 Tag                                   Trial time      Allowed         Used
 ============   ==========   ==========
 USER-AGENT                              0           10                 3
 USER-AGENT-CLIP                       0            0                  0
 ADMIN-AGENT                            0            3                 1
 ADMIN-AGENT-MIG                      0            0                 0

I want to run a grep command that gives me only the USER-AGENT and ADMIN-AGENT lines, and with the Headers.

Like this:

Code:
Tag                                   Trial time      Allowed         Used
 ============   ==========   ==========
 USER                                        0           10                 3
 ADMIN                                       0            3                 1

I have tried a lot, but now iīm stuck


Moderator's Comments:
Mod Comment Sorry if the formatting is a bit messy, but use code tags please, thanks. Check your PM for a guide.

Last edited by zaxxon; 07-21-2014 at 05:55 AM.. Reason: code tags
# 2  
Old 07-21-2014
Please use code tags next time - sorry for the little mess, but copy & paste from terminal into code tags should look fine.

You can try something like:
Code:
license_print | awk 'NR < 3 || $1 ~ /AGENT$/'

or
Code:
license_print | grep -E '^Tag|==|AGENT[ \t]'


Last edited by zaxxon; 07-21-2014 at 06:25 AM.. Reason: removed a leading ^
# 3  
Old 07-21-2014
Sorry for the messy post :-)
I will learn to the next time.

Back to your examples, i donīt get the headers in the printout?

And if i want to get more out of the license_print, also the word PGM, how do i add it?
Code:
license_print | awk 'NR < 3 || $1 ~ /AGENT$/'

# 4  
Old 07-21-2014
Works fine with grep, had just to remove the ^ in front of the ==:
Code:
$ cat infile
Tag                                   Trial time      Allowed         Used
 ============   ==========   ==========
 USER-AGENT                              0           10                 3
 USER-AGENT-CLIP                       0            0                  0
 ADMIN-AGENT                            0            3                 1
 ADMIN-AGENT-MIG                      0            0                 0

$ grep -E '^Tag|==|AGENT[ \t]' infile
Tag                                   Trial time      Allowed         Used
 ============   ==========   ==========
 USER-AGENT                              0           10                 3
 ADMIN-AGENT                            0            3                 1

... and with awk too:
Code:
$ awk 'NR < 3 || $1 ~ /AGENT$/' infile
Tag                                   Trial time      Allowed         Used
 ============   ==========   ==========
 USER-AGENT                              0           10                 3
 ADMIN-AGENT                            0            3                 1

Just in case it is still not working, can you repost your ouput of license_print again using code tags? Thanks.
# 5  
Old 07-21-2014
Perfect, it worked good with grep, but i got a lot off lines, maybe because the file has 4 different sections, thats maybe why i got the header 4 times?
Is it possible to also get the section name?
With awk i didnīt work

Code:
license_print | grep -E 'Tag|==|AGENT[ \t]'
                               ==============
                                          Tag     Trial time      Allowed         Used
=============================================   ============   ==========   ==========
                           USER-AGENT              0           16         0
                                ADMIN-AGENT
                             ================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========
                 ============================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========
                                          ==============================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========

Code:
license_print | awk 'NR < 3 || $1 ~ /AGENT$/'
Status on hardware id: 12da21-918b85
Licenced to hardware id 12da21-918b85
                           USER-AGENT              0           16         0
                                ADMIN-AGENT              0            0         0

And how do i expand this search, if i also would like to get PGM?

If a only print
Code:
license_print

iīll get this:
Code:
license_print
Status on hardware id: 12da21-918b85
Licenced to hardware id 12da21-918b85
License file sequence number 6 with age 1297 hours

                               Port licenses:
                               ==============
                                          Tag     Trial time      Allowed         Used
=============================================   ============   ==========   ==========
                                    USER-AGENT              0           10         3
                        ADMIN-AGENT              0            0         0
 
                             System licenses:
                             ================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========
                               AMC-ENCRYPTION              0           no
                       AUTOMATIC-REGISTRATION              0          yes
 
Key attribute port licenses:
                 ============================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========
                              ALARM-INTERFACE              0            0
 
 Key attribute system licenses:
               ==============================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========
                          AMINISTR-MONITORING              0           no


Last edited by Tzwaj; 07-21-2014 at 08:02 AM.. Reason: *
# 6  
Old 07-21-2014
There is missing the USER-AGENT-CLIP and ADMIN-AGENT-MIP lines you were formerly trying to filter out.
I have edited your output and added these lines.

Code:
$ cat infile
license_print
Status on hardware id: 12da21-918b85
Licenced to hardware id 12da21-918b85
License file sequence number 6 with age 1297 hours

                               Port licenses:
                               ==============
                                          Tag     Trial time      Allowed         Used
=============================================   ============   ==========   ==========
                                   USER-AGENT              0           10            3
                                  ADMIN-AGENT              0            0            0
                              USER-AGENT-CLIP              0            0            0
                              ADMIN-AGENT-MIG              0            0            0

                             System licenses:
                             ================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========
                               AMC-ENCRYPTION              0           no
                       AUTOMATIC-REGISTRATION              0          yes

Key attribute port licenses:
                 ============================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========
                              ALARM-INTERFACE              0            0

 Key attribute system licenses:
               ==============================
                                          Tag     Trial time      Allowed
=============================================   ============   ==========
                          AMINISTR-MONITORING              0           no


$ awk '/Port lic/ {f=1} /System lic/ {f=0} f && $1 ~ /(Tag|AGENT$|===)/ && NF>1 {print}' infile
                                          Tag     Trial time      Allowed         Used
=============================================   ============   ==========   ==========
                                   USER-AGENT              0           10            3
                                  ADMIN-AGENT              0            0            0

If awk is still a problem, please post what OS you are using, thanks.
# 7  
Old 07-21-2014
Thanks a lot.
A final question, i think.

If i also want to get the ADMINISTR-MONITORING line in the same printout, (the same awk) how do i do that?

And if in the future, for example a AGENT line will appear under the header Key attribute port licenses, this awk will find it also?

I really have to learn awk :-)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Issue with Grep

Hi guys, Hope someone can help me with this - I'm sure it's fairly simple but it's driving me mad! (forgive the coding - still new on scripting - come from Windows) I have the following coding for checking whether I want to include a line in a file:- EXTRACT_Date=$(date --date="${PERIOD}"... (6 Replies)
Discussion started by: NickF
6 Replies

2. Shell Programming and Scripting

Issue with grep

Hello, I have an input file that looks like so: LDLR LDLRAD4 VLDLR when I grep "LDLR" I get an output of: LDLR LDLRAD4 VLDLR Since all names have "LDLR" included within them, but all I want the output to be is LDLR I know it can work if I surround the words with pipes for... (5 Replies)
Discussion started by: Rabu
5 Replies

3. Shell Programming and Scripting

Grep issue

Hi Guys, I am new to shell scripting. Need help on grep command. I had a file called file.log which contain below statements. 12 Nov 2013 14:12:17,756 INFO security - Userid: raja, Saved File Instance, Name: , Registry: 23 Nov 2013 14:14:11,777 INFO security - Userid: raja, Saved... (7 Replies)
Discussion started by: Vinoth Kumar G
7 Replies

4. Shell Programming and Scripting

Issue in grep

i have following pattern in file s6:s2 s2:s4 s1:s2:s3:s4:s5:s6 s1 . . Now i want to find occurence of each record in file like s6:s2 occurs twice {once in first record and both occur in 3 record as well} so output should be s6:s2 2 s2:s4 2 s1:s2:s3:s4:s5:s6 :1 s1 : 2 ... (7 Replies)
Discussion started by: sharad.40216
7 Replies

5. Shell Programming and Scripting

Grep issue

Hi All I have a file containing following records: $HEW_TGT_DB2_USER=hbme_bi2 $prmAttunityUser=ais $DS_USER=hbme_bi2 $prmStgUser=hbme_bi2 $prmuser=hbme_bi2 $prmStgPass=hbme_bi2 $prmpwd=hbme_bi2 $prmAttunityUser=ais Say suppose the name of the file is test4.txt When i fire this... (2 Replies)
Discussion started by: vee_789
2 Replies

6. UNIX for Dummies Questions & Answers

Grep issue

more Hello.txt it was a sunny way and i was about to go home. I need to grep and redirect to a new file all the text between 'sunny' and 'go' string above. Note: There may be multiple lines in between the string i need to grep between. If there are multiple 'go' strings it should grep till... (9 Replies)
Discussion started by: mohtashims
9 Replies

7. Shell Programming and Scripting

grep issue

The below command is not working stackmem="$(pmap $1 | grep -i '' | awk '{print $2}'| tr -d ' K')" I need to grep strictly for ----> Regards, Mohtashim (2 Replies)
Discussion started by: mohtashims
2 Replies

8. Shell Programming and Scripting

Grep Issue

<record> <set> <termId>1234</termId> <termType>First</termType> </set> <set> <termId>5678</termId> <termType>Second</termType> </set> </record> This is saved in record.xml Hi I have this sample XML that i am grepping using a shell program. The objective of the task is - based... (7 Replies)
Discussion started by: revertback
7 Replies

9. UNIX for Dummies Questions & Answers

Issue with grep

I have a file that has the following: 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 591066 100.0 ... (5 Replies)
Discussion started by: Pablo_beezo
5 Replies

10. UNIX for Dummies Questions & Answers

issue with grep

using grep, i have a file emp.lst, and i want all those records where "S" or "s" (capital or small) is not there i used this grep emp.lst when i use grep emp.lst i am getting rows with S..but why negate (^) is not working? (3 Replies)
Discussion started by: soujanya_srk
3 Replies
Login or Register to Ask a Question