Search and filter by TAG


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and filter by TAG
# 8  
Old 01-30-2011
Code:
awk '{A[$6]=$0} END{for(i in A) print A[i]}' RS="" infile

This User Gave Thanks to rdcwayx For This Post:
# 9  
Old 01-30-2011
Quote:
Originally Posted by rdcwayx
Code:
awk '{A[$6]=$0} END{for(i in A) print A[i]}' RS="" infile

Thank you, you are my hero Smilie, it works very well...
Now I need to study that code line since I need to filter the output by severity. So for example I need to remove the INFO and WARN severity from the output search.

So, starting with:
Code:
INFO 2011.01.27 20:59:40.489  com.access.protocol.handler.ServerHandler 1234.1291717116.transitionState
  PROT_SOCKET_OPEN   CP connection 1234.1291717116 has changed state to Init

WARN 2011.01.27 20:58:15.242  com.log.SocketConnection doRun
  SOCKET_CLOSE_OK   Closed socket   node SocketQueryListener

FATAL 2011.01.27 20:58:15.242  com.log.SocketConnection doRun
  SOCKET_CLOSE_OK   Closed socket   node SocketQueryListener

ERROR 2011.01.27 20:59:40.690  java.lang.String EventDispatcher.logEvent
  PROT_STATE_CHANGE   Protocol handler  : connectConfirmState [NetworkAccessGroup.ClientGroup.Client.1234] changed {4}

The output should be:
Code:
FATAL 2011.01.27 20:58:15.242  com.log.SocketConnection doRun
  SOCKET_CLOSE_OK   Closed socket   node SocketQueryListener

ERROR 2011.01.27 20:59:40.690  java.lang.String EventDispatcher.logEvent
  PROT_STATE_CHANGE   Protocol handler  : connectConfirmState [NetworkAccessGroup.ClientGroup.Client.1234] changed {4}

Maybe I can play with print statment inserting a simple | grep -v! Smilie

---------- Post updated at 11:05 AM ---------- Previous update was at 10:46 AM ----------

Well i solved using a temporary file. So, first I filter the severity and then I'll filter the tag! Smilie

Code:
cat /home/user/log/Event*.log" | sed -e "/./{H;$!d;}" -e "x;/ERROR/!d;" |  sed -e "/./{H;$!d;}" -e "x;/$1/!d;" >> output.tmp
cat /home/user/log/Event*.log" | sed -e "/./{H;$!d;}" -e "x;/FATAL/!d;" |  sed -e "/./{H;$!d;}" -e "x;/$1/!d;" >> output.tmp

# 10  
Old 01-30-2011
Code:
awk '$1!="INFO" && $1!="WARN"{A[$6]=$0} END{for(i in A) print A[i]}' RS="" infile

This User Gave Thanks to vgersh99 For This Post:
# 11  
Old 01-30-2011
Quote:
Originally Posted by vgersh99
Code:
awk '$1!="INFO" && $1!="WARN"{A[$6]=$0} END{for(i in A) print A[i]}' RS="" infile

Ah! Ok, as always, all in one row is better! Smilie
is there a way to count how many TAG occours? I mean this is filtering by "PROT_SOCKET_OPEN", "SOCKET_CLOSE_OK", and so on....

I would like to count how many time for example the PROT_SOCKET_OPEN event occour and if possible print near the output like:

Code:
ERROR 2011.01.27 20:59:40.690  java.lang.String EventDispatcher.logEvent
  (120) PROT_STATE_CHANGE   Protocol handler  : connectConfirmState [NetworkAccessGroup.ClientGroup.Client.1234] changed {4}


Last edited by Lord Spectre; 01-30-2011 at 12:26 PM..
# 12  
Old 01-30-2011
Code:
nawk '$1!="INFO" && $1!="WARN"{A[$6]=$0;c[$6]++} END{for(i in A) print A[i]," changed [" c[i] "]"}' RS="" myFile

This User Gave Thanks to vgersh99 For This Post:
# 13  
Old 01-30-2011
It append the "counter" at the end of the single event not in the middle as my example, but it's perfect also as is.....
Also I don't have nawk, but seem it works also with awk!

Many many thanks to all the people who help me!
Now it's time to study and make experiments with all the suggested commands! Smilie
# 14  
Old 01-30-2011
Code:
nawk '$1!="INFO" && $1!="WARN"{A[$6]=$0;c[$6]++} END{for(i in A) {n=index(A[i],ORS);print substr(A[i],1,n) "(" c[i] ")" substr(A[i],n+1)}}' RS="" myFile

This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed search and replace after xml tag

Hi All, I'm new to sed. In following XML file <interface type='direct'> <mac address='52:54:00:86:ce:f6'/> <source dev='eno1' mode='bridge'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> ... (8 Replies)
Discussion started by: varunrapelly
8 Replies

2. Shell Programming and Scripting

Search for a tag and display a message if not found.

Hi All, I am working with a XML file. Below is part for the file. <Emp:Profile> <Emp:Description>Admin</Emp:Description> <Emp:Id>12347</Emp:Id> </Emp:Profile> <Emp:Profile> ... (7 Replies)
Discussion started by: Girish19
7 Replies

3. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

4. Shell Programming and Scripting

Search for a html tag and print the entire tag

I want to print from <fruits> to </fruits> tag which have <fruit> as mango. Also i want both <fruits> and </fruits> in output. Please help eg. <fruits> <fruit id="111">mango<fruit> . another 20 lines . </fruits> (3 Replies)
Discussion started by: Ashik409
3 Replies

5. Shell Programming and Scripting

Need an efficient way to search for a tag in an xml file having millions of rows

Hi, I have an XML file with around 1 billion rows in it and i am trying to find the number of times a particular tag occurs in it. The solution i am using works but takes a lot of time (~1 hr) .Please help me with an efficient way to do this. Lets say the input file is <Root> ... (13 Replies)
Discussion started by: Sheel
13 Replies

6. Shell Programming and Scripting

Multiple Tag Search and Printing

Scenario: The following text belongs to a .doc file File: check1.asmFunction: MonksTag: NoTag: 001Tag: YesTag: 002File: check2.asmFunction: Perl MonksTag: YesTag: 003Tag: NoTag: 004File: check3.asmFunction: ExpertsTag: NoTag: 005Tag: NoTag: 006Function: Perl ExpertsTag: NoTag: 007Tag: YesTag: 008... (1 Reply)
Discussion started by: rajkrishna89
1 Replies

7. Shell Programming and Scripting

search pattern and mark/tag

Hi All, I have to search for patterns from a pattern file in a file and mark the matching lines. Input File: Student1 60 30 Student2 71 91 Student3 88 98 Pattern file: Student1 Fail Student2 Pass Student2 Pass Desired output: Student1 60 30 Fail Student2 71 91 Pass (5 Replies)
Discussion started by: saint2006
5 Replies

8. UNIX for Dummies Questions & Answers

Search and filter between two files

Hello, I have two files in this form that consist of three columns, a name (L*contig*), the length (length=**) and the sequence LT_file.txt LTcontig1 length=13 acccatgctttta LTcontig5 length=8 ggattacc LTcontig8 length=20 ccattgaccgtacctgatcg LTcontig23 length=5 accta and... (5 Replies)
Discussion started by: FelipeAd
5 Replies

9. Shell Programming and Scripting

Search for particular tag and arrange as coordinates

Hi I have a file whose sample contents are shown here, 1.2.3.4->2.4.2.4 a(10) b(20) c(30) 1.2.3.4->2.9.2.4 a(10) c(20) 2.3.4.3->3.6.3.2 b(40) d(50) c(20) 2.3.4.3->3.9.0.2 a(40) e(50) c(20) 1.2.3.4->3.4.2.4 a(10) c(30) 6.2.3.4->2.4.2.5 c(10) . . . . Here I need to search... (5 Replies)
Discussion started by: AKD
5 Replies

10. UNIX for Dummies Questions & Answers

ldap search filter

Hi, I am trying to do an ldapsearch with a filter that checks the uid and the userpassword: $filter= "(&(uid=$user) (userpassword=$password)"; $objs = $ldap->search( base => $basedn, filter => "($filter)"); i based it on this example i found on CPAN: $mesg = $ldap->search( ... (2 Replies)
Discussion started by: tine
2 Replies
Login or Register to Ask a Question