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

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.

10239, Simon MEREDITH HARDY|1548550739844

server.log

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>  
 

it is not clear how your program works with such the logfile and where figure 10239 came from?

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

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

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

Something tells me that everything is not so simple :slight_smile:

sed -rn '/error_code>50001111/ s/.*<order_id>([^<]*).*/\1/p' server.log

from mailx man

Could this be the case?

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?