Need to search specific string in a log


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need to search specific string in a log
# 1  
Old 12-03-2014
Need to search specific string in a log

Hi,

I have a log file containing below data

Code:
12/3/14 12:43:59 AM WIT |Performance threshold: elapsed time = 3152 milliseconds,<PerformSingleConfigurationChangeOutput><ProductOrderID>28790477</ProductOrderID><ResponseStatus><Status>true</Status></ResponseStatus></PerformSingleConfigurationChangeOutput>

I need to search for elapsed time = 3152 milliseconds and ProductOrderID>28790477</ProductOrderID>

Please note that in elapsed time = 3152 milliseconds, value 3152 is changing, same in <ProductOrderID>28790477</ProductOrderID>.

in my script, to search the value 3152 and 28790477, I need to use the keywords elapsed time = and ProductOrderID>.

so for my final output, I would have 3152 and 28790477.

Code:
ElapsedTime: 3152
 ProductOrderId: 28790477

Thank you

Last edited by csm231; 12-03-2014 at 04:35 AM..
This User Gave Thanks to csm231 For This Post:
# 2  
Old 12-03-2014
Hello csm231,

Welcome to forum, thank you for using code tags for input, there is a option named icode tags in tool bar at right most corner
you can use that for command names. Following awk (Use of icode here) may help you.

Code:
awk '{match($0,/elapsed time.*milliseconds/);print "ElapsedTime: " substr($0,RSTART+15,RLENGTH-27)}' Input_file

Output will be as follows.
Code:
ElapsedTime: 3152

I haven't seen <ProductOrderID>28790477</ProductOrderID> (Use of icode here) mentioned by you in provided input so didn't include it.


Thanks,
R. Singh
# 3  
Old 12-03-2014
Thank you for your reply RavinderSingh13, I have edited my post to include <ProductOrderID>28790477</ProductOrderID>.

Code:
12/3/14 12:43:59 AM WIT |Performance threshold: elapsed time = 3152 milliseconds, <PerformSingleConfigurationChangeOutput><ProductOrderID>28790477</ProductOrderID><ResponseStatus><Status>true</Status></ResponseStatus></PerformSingleConfigurationChangeOutput>

I will try to use the command you have made, thank you very much.
Moderator's Comments:
Mod Comment When in-line text in a sentence needs to be shown in constant width font, use ICODE tags. When a long line or multiple lines of code, sample input, or sample output needs to be shown, use CODE tags.

Last edited by Don Cragun; 12-03-2014 at 01:06 AM.. Reason: Change ICODE tags to CODE tags for data in a long line.
# 4  
Old 12-03-2014
Hello csm231,

Following may help you in same. Also for commands/complete input we can use code tags. For command names or very small code we can use icodes,
if I am mentioning a command name in a sentence so icode will be helpful else code tags are our friends to show our complete code/commands.

Following Use of icode awk may help you.
(Use of Code tags as follows)

Code:
awk '{match($0,/elapsed time.*milliseconds/);print "ElapsedTime: " substr($0,RSTART+15,RLENGTH-27);match($0,/<ProductOrderID>.*<\/ProductOrderID>/);print "ProductOrderId: " substr($0,RSTART+16,RLENGTH-33)}'  Input_file

Output will be as follows. (Use of Code tags)
Code:
ElapsedTime: 3152
ProductOrderId: 28790477

For more information on rules kindly go through the rules of forums in following URL, welcome to forum again. Enjoy learning.

https://www.unix.com/misc.php?do=cfrules


Thanks,
R. Singh

Last edited by RavinderSingh13; 12-03-2014 at 01:08 AM.. Reason: Removed smilie sign which came by using :) together in text
# 5  
Old 12-03-2014
Thank you again RavinderSingh13 and sory for the wrong use of code tags.. Smilie
# 6  
Old 12-03-2014
With (GNU) sed try
Code:
sed 's/.*elapsed time = \([0-9]*\).*<ProductOrderID>\([0-9]*\).*/ElapsedTime: \1\nProductOrderID: \2/' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. UNIX for Dummies Questions & Answers

Search specific string logfile specific date range

Hi, I have logfile like this.. === 2014-02-09 15:46:59,936 INFO RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header === 2015-02-09... (8 Replies)
Discussion started by: kishk
8 Replies

3. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

4. UNIX for Dummies Questions & Answers

How can I search and change an specific string in a file

Dear All, New to Linux/Unix OS, my Linux version is 2010 x86_64 x86_64 x86_64 GNU/Linux As titled, I wonder if you can help to provide a solution to find and change an specific string in a file The file include a lots of data in following configuration but might be various in... (3 Replies)
Discussion started by: axel
3 Replies

5. Shell Programming and Scripting

search-word-print-specific-string

Hi, Our input xml looks like: <doc> <str name="account_id">1111</str> <str name="prd_id">DHEP155EK</str> </doc> - <doc> <str name="account_id">6666</str> <str name="prd_id">394531662</str> </doc> - <doc> <str name="account_id">6666</str> <str... (1 Reply)
Discussion started by: Jassz
1 Replies

6. UNIX for Dummies Questions & Answers

How to search all the files in a directory for a specific string

Hi Guys, I want to search the content of all the files (of a particular type like .txt) in a directory for a specific string pattern. Can anyone help me? Thanks (7 Replies)
Discussion started by: mwrg
7 Replies

7. Shell Programming and Scripting

Search a specific string

Hi, I have following requirement. Pls suggest. To search a string in a file which is combination of character and number(always 9 digit, but numeric). if found then caputure the exit return code as 0 else 1 , if 0 then next job can be triggerd. If exit code is 1, should return a failure... (10 Replies)
Discussion started by: zooby
10 Replies

8. UNIX for Dummies Questions & Answers

Search for string between specific lines of code in vi

Hi, I am on an AIX Unix box and I am trying to search for a string in between specified lines of code when I vi a file. I can use the '/string' to search for the string through out the file, but can we only search in between specific lines. I can use the below sed command to search for the... (8 Replies)
Discussion started by: coolavi
8 Replies

9. Shell Programming and Scripting

search string during a specific time frame

Can someone please help me with searching a string during a specific time frame. Below is the format of the time from my log file. "GET /AAM2009_wherewereheaded.wmv HTTP/1.1" 200 52307085 The search string I need is "AAM2009_wherewereheaded.wmv" I need to search the number of... (1 Reply)
Discussion started by: tadi18
1 Replies

10. UNIX for Dummies Questions & Answers

Search all files for specific string

Hi Friends, How can I search all files in all slices on a unix system for a particular string within the file. e.g search string 'oracle' Thanks (4 Replies)
Discussion started by: sureshy
4 Replies
Login or Register to Ask a Question