How to search the multiple strings in app server.log?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to search the multiple strings in app server.log?
# 1  
Old 01-28-2019
How to search the multiple strings in app server.log?

Hi Team,

Could you please suggest the below requirement.

using the below server log, i just want only the order_id with combination of customer name , error code value as 5000111 & amount value using the shell script
i tired using the command
Code:
grep "error_code>50001111" server.log.2019-01-27 |awk -F"order_id" '{print $2}' |awk -F">" '{print $2}' |awk -F"<" '{print $1}'

After using the command, i got the below output.
Code:
10239, Simon MEREDITH HARDY|1548550739844

server.log

Code:
response: <transaction> 
 <on_test_gateway type="boolean">false</on_test_gateway>  <created_at type="dateTime">2019-01-27T00:59:00Z</created_at>
 <updated_at type="dateTime">2019-01-27T00:59:01Z</updated_at>  <succeeded type="boolean">false</succeeded>
 <state>gateway_processing_failed</state>  <token>15789589</token> 
 <transaction_type>Purchase</transaction_type>  <order_id>154896, Simon MEREDITH HARDY|1548550739844</order_id>  
 <ip nil="true"/>  <description nil="true"/>  <email nil="true"/>  <merchant_name_descriptor nil="true"/> 
 <merchant_location_descriptor nil="true"/>  <gateway_specific_fields nil="true"/>  <gateway_specific_response_fields> 
 </gateway_specific_response_fields>  <gateway_transaction_id>0</gateway_transaction_id>  <gateway_latency_ms type="integer">717</gateway_latency_ms>
 <amount type="integer">1150</amount>  <currency_code>EUR</currency_code>  <retain_on_success type="boolean">false</retain_on_success>  <payment_method_added type="boolean">false</payment_method_added>  <message></message> 
 <gateway_token>A11011452578589</gateway_token>  <gateway_type>ogone</gateway_type>  <shipping_address>    <name>S P MEREDITH HARDY</name>  
 <address1 nil="true"/>    <address2 nil="true"/>    <city nil="true"/>    <state nil="true"/>    <zip nil="true"/>    <country nil="true"/>  
 <phone_number nil="true"/>  </shipping_address>  <response>    <success type="boolean">false</success>    <message></message>    <avs_code nil="true"/> 
 <avs_message nil="true"/>    <cvv_code nil="true"/>    <cvv_message nil="true"/>    <pending type="boolean">false</pending>    <result_unknown type="boolean">false</result_unknown> 
 <error_code>50001111</error_code>    <error_detail nil="true"/>    <cancelled type="boolean">false</cancelled>    <fraud_review nil="true"/>    <created_at type="dateTime">2019-01-27T00:59:01Z</created_at>  
 <updated_at type="dateTime">2019-01-27T00:59:01Z</updated_at>  </response>  <api_urls>  </api_urls>  <payment_method>    <token>A11011452578589</token>


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 01-28-2019 at 10:50 AM.. Reason: Added CODE tags.
# 2  
Old 01-28-2019
it is not clear how your program works with such the logfile and where figure 10239 came from?

--- Post updated at 14:44 ---

Code:
grep -o "Simon[^<]*" server.log

# 3  
Old 01-28-2019
With a few assumptions from my side, like
- that entire sample above is one single line (else your grep wouldn't work)
- you really want just the string between <order_id> and </order_id>
- the 10239 is a typo from your side
how about



Code:
awk '/error_code>50001111/ {match ($0, /<order_id>.*<\/order_id>/); print substr ($0, RSTART+10, RLENGTH-21)}' file
154896, Simon MEREDITH HARDY|1548550739844

This User Gave Thanks to RudiC For This Post:
# 4  
Old 01-28-2019
Something tells me that everything is not so simple Smilie
Code:
sed -rn '/error_code>50001111/ s/.*<order_id>([^<]*).*/\1/p' server.log

# 5  
Old 01-28-2019
sorry for typo message .

Yeah , the above recommendation is fantastic and its working fine using the above command .

if the above error message occurred in log, i would like to get the error in email alert.

--- Post updated at 08:36 AM ---

Code:
#!/bin/bash 
SERV=/home/skyline1/jboss-eap-7.0/standalone/log
cd /home/skyline1/jboss-eap-7.0/standalone/log
FDATE=`date '+%Y-%m-%d'`
awk '/error_code>50001111/ {match ($0, /<order_id>.*<\/order_id>/); print substr ($0, RSTART+10, RLENGTH-21)}' server.log /home/skyline1/jboss-eap-7.0/standalone/log > paymentfailed.log
cat paymentfailed.log | mailx -s " ELM Checks on `date +%d-%b-%Y` " -c vbathula918@gmail.com

i have tried the above shell script.some where the problem is occuring ..can any one please suggest here
# 6  
Old 01-28-2019
from mailx man
Quote:
-s ...be careful to quote subjects containing spaces.
Could this be the case?

Last edited by nezabudka; 01-28-2019 at 01:05 PM..
# 7  
Old 01-28-2019
Wouldn't it be nice to show WHAT the problem is, and when it occurs? Do the individual elements work, i.e. was the "paymentfailed.log" file created? Does the mailx command work on itself (no extras, no (or simple) subject, no options, ...)?
Do you need the "paymentfailed.log" for later processing? If not, pipe the awk output immediately into mailx.
Why do you define the SERV and FDATE variables and then don't use them?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search between two strings for multiple occurances

i search between two strings viz <app-deployment> & </app-deployment> and save the contents in a new file using the code snippet below. sed -n "/<app-deployment/,/<\/app-deployment>/p" deploy.tmp >found1.tmpBut if the search string apprears more than once in the file then how can i store the... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Multiple search strings replaced with single string

Hi, I need someone's help in writing correct perl code. I implemented following code for "multiple search strings replaced with single string". ========================================================= #!/usr/bin/perl my $searchStr = 'register_inst\.write_t\(' |... (2 Replies)
Discussion started by: chettyravi
2 Replies

3. Shell Programming and Scripting

Whether we can search multiple strings using or in grep -F

Hi, Whether we can search multiple strings using or in grep -F In Generally, grep -F "string1" "filename.txt" How to search for multiple string using grep -F as we using grep grep "string1\|string2" "filename.txt" Regards, Nanthagopal A (10 Replies)
Discussion started by: nanthagopal
10 Replies

4. Shell Programming and Scripting

Search & Replace: Multiple Strings / Multiple Files

I have a list of files all over a file system e.g. /home/1/foo/bar.x /www/sites/moose/foo.txtI'm looking for strings in these files and want to replace each occurrence with a replacement string, e.g. if I find: '#@!^\&@ in any of the files I want to replace it with: 655#@11, etc. There... (2 Replies)
Discussion started by: spacegoose
2 Replies

5. Shell Programming and Scripting

Search multiple Strings in a File

Hi I want to search multiple strings in a file . But the search should start with "From" Keyword and end with before "Where" keyword. Please suggest me. Thanks (2 Replies)
Discussion started by: sboss
2 Replies

6. Shell Programming and Scripting

Search multiple strings on a file and copy the string next to it

I tried awk for this, but failed <or my code is not correct? I dont know>. Can anyone help me on this? ---------- Post updated at 08:34 PM ---------- Previous update was at 08:29 PM ---------- my working file looks like this: <empty> <empty> <empty> NAME :ABC AGE :15 GENDER... (6 Replies)
Discussion started by: kingpeejay
6 Replies

7. Shell Programming and Scripting

Search for multiple strings in specific position

Hi, I need to search for some strings in specific positions in a file. If the strings: "foo1", "foo2" or "foo3" is on position 266 or position 288 in a file i want the whole line printed. Any idea how to do it? (5 Replies)
Discussion started by: HugoH
5 Replies

8. UNIX for Dummies Questions & Answers

Search for multiple strings and mail accordingly

Hi, I need to find if there is any error in the last few lines of the log file and send a mail accordingly.For example, Following errors can be logged in the log file. ERR_1="DB Connection not established" ERR_2="Server Unloading" I need to find if these errors are found in the log file and... (3 Replies)
Discussion started by: AnneAnne
3 Replies

9. Shell Programming and Scripting

How to search multiple strings in a file

Hi All, I want to search all the ksh scripts that has following details. 1. Search for "exit 0" 2. Search for "sqlldr" or sqlplus" 3. In the above files i want to search for all the script that has no "case" in it. Please advice. Thanks, Deep (2 Replies)
Discussion started by: deepakpv
2 Replies

10. Shell Programming and Scripting

Problem to search multiple strings

Hi all, I am search a string from a file using following command, I want to pick the message ( I.e print $5) from the lookup file if and only if both $hostname and $instancename match. Message=`cat $lookup_tbl| awk '/'$category'/ {if ('$hostname' == '$2' || '$instancename' == '$3') print $5}'`... (2 Replies)
Discussion started by: sudhish
2 Replies
Login or Register to Ask a Question