Complex string search query.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Complex string search query.
# 1  
Old 05-03-2013
Blade Complex string search query.

Hi,
I wish to find the latest occurance of the below string in my log file.

Quote:
<t1:Notify><r1:Prod>Tomcat</t1:Prod><z1:Number>331489</z1:Number>
Once found, I need to search the below string after the above string

Quote:
<k1:Event>Status</k1:Event><y1:Status>passed</y1:Status>
and display this

Code:
 
Request 331489 has passed

or
Code:
 
Request 331489 has failed

I would like my query to be platform independent.
# 2  
Old 05-03-2013
As per my understanding below might work


Code:
awk -F"[<>]" '/Notify/&&/Number/{var=$9};/Status/&&/Event/{var1=$7}END{print "Request "var" has "var1}' filename

# 3  
Old 05-03-2013
Quote:
Originally Posted by vidyadhar85
As per my understanding below might work


Code:
awk -F"[<>]" '/Notify/&&/Number/{var=$9};/Status/&&/Event/{var1=$7}END{print "Request "var" has "var1}' filename


I need to pass the request number as argument to the script however, passed or failed is not a variable but something that the log file will have that I need to read and display for this request number.

I did not understand what does two variables and $9 and $ 7 used for in your suggestion ??
# 4  
Old 05-03-2013
Quote:
Originally Posted by mohtashims
I need to pass the request number as argument to the script however, passed or failed is not a variable but something that the log file will have that I need to read and display for this request number.

I did not understand what does two variables and $9 and $ 7 used for in your suggestion ??
This is what happens with half requirement Smilie Anyways post the content of the file and if you wanna pass number as argument and check the next passed/failed after that number we can do it with sed or awk..

Let us know your full req so that you wont get dispointed again...
# 5  
Old 05-03-2013
Quote:
Originally Posted by vidyadhar85
pass number as argument and check the next passed/failed after that number we can do it with sed or awk..

Let us know your full req so that you wont get dispointed again...
That's exactly the requirement as you quoted above, however there can be multiple entries for the number being passed in the log file. What I wish to know is the last i.e. the latest entry for that request number and the pass fail msg for the same.

Kindly help.
# 6  
Old 05-03-2013
You may want to try
Code:
$ REQ=331489
$ tac file |
sed -n  "/^.*\(passed\|failed\).*$/     {s//\1./;h}
         /^.*\($REQ\).*$/               {s//Request \1 has /;G;s/\n//;p}
        "
Request 331489 has passed.

# 7  
Old 05-03-2013
Quote:
Originally Posted by RudiC
You may want to try
Code:
$ REQ=331489
$ tac file |
sed -n  "/^.*\(passed\|failed\).*$/     {s//\1./;h}
         /^.*\($REQ\).*$/               {s//Request \1 has /;G;s/\n//;p}
        "
Request 331489 has passed.

This did not work... Below is what i did

more request.sh

Code:
REQ=$1
tac $2 |
sed -n  "/^.*\(passed\|failed\).*$/     {s//\1./;h}
         /^.*\($REQ\).*$/               {s//Request \1 has /;G;s/\n//;p}
                 "

Running the script like:

Code:
./request.sh 3422 /tmp/NSL.out

Output
Quote:
bash: tac: command not found
Thus, I have no solutions yet Smilie

Last edited by mohtashims; 05-03-2013 at 07:29 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search the specific content from the complex file

Hi, I have a file with complex data without delimiter, have requirement to fetch the specific record based on some charcters. here is my file data ... (12 Replies)
Discussion started by: Riverstone
12 Replies

2. Shell Programming and Scripting

Complex Query regarding folder size

Hi, I provide the path to a folder. I would like so drill in each folder inside the folder i gave and show me the size in human readable form du -sh <folder-name> of the top 8 folders with maximum sizes. For example: Path of the folder: "/opt/app/myapp" has these directories. ls... (2 Replies)
Discussion started by: mohtashims
2 Replies

3. Shell Programming and Scripting

awk command for complex search and print

Input: 9999~cbc~100~209~ozzxczcz~10001001001~100~abc10 123~a~sdklfjl~sldoi~~~ksjdfnkjsdf~123456 125~g~sdklfjl~slsdfsdfsdfsdfdoi~~~~~~~~ksjdfnkjsdf~345 127~wera~sdklfjl~sldoi~~~ksjdfnkjsdf~123 128~awer~swerwerdklfjl~sldoi~~~ksjdfnkjsf~1da2345... (7 Replies)
Discussion started by: onesuri
7 Replies

4. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Shell Programming and Scripting

Complex query

A file whose location i am not aware of contains the below text <url>jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(FAILOVER=on)(ADDRESS=(PROTOCOL=TCP) (HOST=ngm2sn1p2-vip.mybank.net)(PORT=4001))(ADDRESS=(PROTOCOL=TCP)(HOST=ngm2sn2p2-vip.mybank.net)... (1 Reply)
Discussion started by: mohtashims
1 Replies

7. Web Development

Complex MySQL Query(s)

Hi all, I have a bit of an issue, I am working on a bit of a CMDB for a friend, it's to do with real estate. Anyway, this is my situation. I have a table which contains all the properties (forsale, sold, etc) in the DB named "property". Now, this is what I want to achieve, I wish to... (5 Replies)
Discussion started by: STOIE
5 Replies

8. Shell Programming and Scripting

Complex search and output

Hi, I have somewhat of a complex task at hand. I am on a HP-UX box and I need to search for information embedded in files, further embedded into a file/folder structure. I compiled a list of information that I need found: File=list.csv DATE FIELD 1 FIELD2... (2 Replies)
Discussion started by: doza22
2 Replies

9. Shell Programming and Scripting

Complex Search/Replace Multiple Files Script Needed

I have a rather complicated search and replace I need to do among several dozen files and over a hundred occurrences. My site is written in PHP and throughout the old code, you will find things like die("Operation Aborted due to....."); For my new design skins for the site, I need to get... (2 Replies)
Discussion started by: UCCCC
2 Replies

10. Programming

Need help with complex SQL query (Sybase)

Hello, I have three tables. I need an SQL query (preferably Sybase) that will return all of the stringID values of table B where the following conditions exist: (1) B.intID = A.intID (2) B.intID != C.intID or (B.intID = C.intID and (C.v1 = 0 or C.v2... (2 Replies)
Discussion started by: chatieremerrill
2 Replies
Login or Register to Ask a Question