Sponsored Content
Top Forums Shell Programming and Scripting extract xml tag based on condition Post 302488209 by durden_tyler on Sunday 16th of January 2011 03:37:39 AM
Old 01-16-2011
Quote:
Originally Posted by angshuman
...
Code:
<INVOICES>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>1234</INVOICE_NO>
</INVOICE>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>2345</INVOICE_NO>
</INVOICE>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>3456</INVOICE_NO>
</INVOICE>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>5678</INVOICE_NO>
</INVOICE>
</INVOICES>

I need to extract all the <INVOICE>...........</INVOICE> provided the value of INVOICE_NO = 2345 and 5678.
...
Maybe something like this?

Code:
$
$ # display the contents of the xml file
$ cat f1.xml
<INVOICES>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>1234</INVOICE_NO>
</INVOICE>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>2345</INVOICE_NO>
</INVOICE>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>3456</INVOICE_NO>
</INVOICE>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>5678</INVOICE_NO>
</INVOICE>
</INVOICES>
$
$ # Perl one-liner to extract the information
$ perl -lne 'BEGIN{undef $/} while(/(<INVOICE>(.*?)<\/INVOICE>)/sg) {$x=$1; print $x if $2 =~ /2345|5678/}' f1.xml
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>2345</INVOICE_NO>
</INVOICE>
<INVOICE>
<NAME>Customer A</NAME>
<INVOICE_NO>5678</INVOICE_NO>
</INVOICE>
$
$

tyler_durden
These 2 Users Gave Thanks to durden_tyler For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract value inside <text> tag for a particular condition.

Hi All! I have obtained following output from a tool "pdftohtml" :: So, my input is as under: <text top="246" left="160" width="84" height="16" font="3">Business purpose</text> <text top="260" left="506" width="220" height="16" font="3">giving the right information and new insights... (3 Replies)
Discussion started by: parshant_bvcoe
3 Replies

2. UNIX for Dummies Questions & Answers

Unable to extract a tag from a very long XML message

Hi I have a log file which contain XML message. I want to extract the value between the tag : <businessEventId>13201330</businessEventId> i.e., 13201330. I tried the following commands but as the message is very long, unable to do it. Attached is the log file. Please provide inputs. --... (3 Replies)
Discussion started by: Sapna_Sai
3 Replies

3. Shell Programming and Scripting

how to extract the info in the tag from a xml file

Hi All, Do anyone of you have any idea how to extract each<info> tag to each different file. I have 1000 raw files, which come in every 15 mins.( I am using bash) I have tried my script as below, but it took hours to finish, which is inefficiency. perl -n -e '/^<info>/ and open FH,">file".$n++;... (2 Replies)
Discussion started by: natalie23
2 Replies

4. Shell Programming and Scripting

Extract multiple xml tag value into CSV format

Hi All, Need your assistance on another xml tag related issue. I have a xml file as below: <INVOICES> <INVOICE> <BILL> <BILL_NO>1234</BILL_NO> <BILL_DATE>01 JAN 2011</BILL_DATE> </BILL> <NAMEINFO> <NAME>ABC</NAME> </NAMEINFO> </INVOICE> <INVOICE> <BILL> <BILL_NO>5678</BILL_NO>... (12 Replies)
Discussion started by: angshuman
12 Replies

5. Shell Programming and Scripting

Extract TAG name and XPATH from XML file via shellscript

Hi, Here is a sample xml file and expected output. I need to extract the element/tag name (not value) and xpath (sample output.txt). But the main problem is I put here one simple xml file where I can clearly see the number of elements, but in real time I have a xml file which have over 500... (18 Replies)
Discussion started by: BithunC
18 Replies

6. Shell Programming and Scripting

Extract XML tag value from file

Hello, Hope you are doing fine. I have an log file which looks like as follows: Some junk text1 Date: Thu Mar 15 13:38:46 CDT 2012 DATA SENT SUCCESSFULL: Some jun text 2 Date: Thu Mar 15 13:38:46 CDT 2012 DATA SENT SUCCESSFULL: ... (3 Replies)
Discussion started by: srattani
3 Replies

7. Shell Programming and Scripting

Help with XML tag value extraction based on matching condition

sample xml file part <DocumentMinorVersion>0</DocumentMinorVersion> <DocumentVersion>1</DocumentVersion> <EffectiveDate>2017-05-30T00:00:00Z</EffectiveDate> <FollowOnFrom> <ContractRequest _LoadId="export_AJ6iAFoh6g0rE9"> <_LocalId>CRW2218451</_LocalId> ... (4 Replies)
Discussion started by: paul1234
4 Replies

8. Shell Programming and Scripting

Help with XML tag value extraction based on condition

sample xml file part <?xml version="1.0" encoding="UTF-8"?><ContractWorkspace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" _LoadId="export_AJ6iAFmh+pQHq1" xsi:noNamespaceSchemaLocation="ContractWorkspace.xsd"> <_LocalId>CW2218471</_LocalId> <Active>true</Active> ... (3 Replies)
Discussion started by: paul1234
3 Replies

9. Shell Programming and Scripting

Help with tag value extraction from xml file based on a matching condition

Hi , I have a situation where I need to search an xml file for the presence of a tag <FollowOnFrom> and also , presence of partial part of the following tag <ContractRequest _LoadId and if these 2 exist ,then extract the value from the following tag <_LocalId> which is "CW2094139". There... (2 Replies)
Discussion started by: paul1234
2 Replies

10. UNIX for Beginners Questions & Answers

Replacing tag based on condition

Hi All, I am having a file like below. The file will having information about the records.If you see the file the file is header and data. For example it have 1 men tag and the tag id will be come after headers. The change is I want to convert All pets tag from P to X. I did a sed like below... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies
Vend::Payment::NetBilling(3pm)				User Contributed Perl Documentation			    Vend::Payment::NetBilling(3pm)

Interchange NetBilling Support
       Vend::Payment::NetBilling $Revision: 1.6 $

SYNOPSIS
&charge=netbilling or [charge route=netbilling param1=value1 param2=value2] PREREQUISITES
LWP::UserAgent LWP::Protocol::https Digest::MD5 All of these need be present and working. DESCRIPTION
The Vend::Payment::NetBilling module implements the netbilling() routine for use with Interchange. It is compatible on a call level with the other Interchange payment modules. In theory (and even usually in practice) you could switch from another payment module to NetBilling with a few configuration file changes. SETUP
To enable this module, place this directive in your "interchange.cfg" file: Require module Vend::Payment::NetBilling This must be in interchange.cfg or a file included from it. Make sure CreditCardAuto is off which is the default in the Standard ecommerce demo. The mode can be named anything, but the "gateway" parameter must be set to "netbilling". To make it the default payment gateway for all credit card transactions in a specific catalog, you can set in "catalog.cfg": Variable MV_PAYMENT_MODE netbilling SETTINGS
Vend::Payment::NetBilling uses several of the standard settings from Interchange payment. Any time we speak of a setting, it is obtained either first from the tag/call options, then from an Interchange order Route named for the mode, then finally a default global payment variable, For example, the "id" parameter would be specified by: [charge route=netbilling id=YourNetBillingID] or Route netbilling id YourNetBillingID or Variable MV_PAYMENT_ID YourNetBillingID The settings are: amount Amount for the transaction. Defaults to the checkout total after all shipping, taxes discounts, and other levies have been applied. getid The path to the getid script on the NetBilling secure server. Defaults to "/gw/native/getid1.0". host The domain name of the NetBilling secure server. Defaults to "secure.netbilling.com". id This is your account and sitetag separated by a colon (ACCOUNT:SITETAG). ACCOUNT is the number of your Netbilling merchant or agent account, as a 12-character string. Required for ALL transactions. SITETAG is the site tag of your website configured in the Netbilling system. Required for membership transactions, optional for others. Global parameter is MV_PAYMENT_ID. poll The path to the poll script on the NetBilling secure server. Defaults to "/gw/native/poll1.0". port The port to connect to on the NetBilling secure server. Defaults to the standard https port(443). remap This remaps the form variable names to the ones needed by NetBilling. remote_host Hostname of customer for NetBilling to record for this transaction. Defaults to the session remote host. remote_ip IP address of customer for NetBilling to record for this transaction. Defaults to the session IP. retries Number of times to attempt a connection to the NetBilling secure server before giving up. Defaults to 3. script The path to the NetBilling direct mode 2.1 script on the NetBilling secure server. Defaults to "/gw/native/direct2.1". secret Your NetBilling Order Integrity Key, set in the NetBilling admin interface in step 11 of 'Fraud Defense'. Global parameter is MV_PAYMENT_SECRET. trans_id Netbilling Transaction ID returned from a previous transaction. Used for 'REFUND' type transactions, the amount of the refund/Void and other relevant data will be taken from the original transaction data. transaction The type of transaction to be run. Valid values are: Interchange NetBilling ----------- ---------- avs AVS Address verification only, no charges auth AUTH Pre-Auth a charge card for later capture return CREDIT Credit the charge/ACH account instead of charging it reverse REFUND Will attempt a VOID or a Refund of a previous 'SALE' sale SALE Standard charge/ACH transaction settle CAPTURE Capture a Pre-Authed charge void REFUND Will attempt a VOID or a Refund of a previous 'SALE' abort ABORT Will abort a pending capture The "reverse" and "void" transactions are both sent as a "REFUND" because NetBilling determines internally whether to "VOID" or "REFUND" based on if the original transaction has been batched out yet. The default is "sale". type The payment type. Set to "K" or any string with the word "check" in it for online checking. Any other value for charge. If left unset or blank will default to the "mv_order_profile" form value or CGI variable which can be "remap"ped to a different actual form name (see "remap"). If everything is blank this defaults to charge. VALUES
Values can be obtained either from processed or raw CGI values. The CGI names can be "remap"ped with the "remap" setting above in case your form names are different. address1 Customer's shipping street address and also the default for b_address1. auth_code Force code provided by credit card processor. Optional. b_address1 Customer's billing street address. Required for address verification. Defaults to address1. b_city Customer's billing city. Required for address verification. Defaults to city. b_country Customer's billing country. Required for address verification. Defaults to country. b_fname Customer's billing first name. Required for address verification. Defaults to fname. b_lname Customer's billing last name. Required for address verification. Defaults to lname. b_state Customer's billing state/province. Required for address verification. Defaults to state. b_zip Customer's billing zip/postal code. Required for address verification. Defaults to zip. check_account Checking account number. Required for ACH transactions. check_dl Optional driver's license number field, but necessary for proper online check fraud screening. In any case, only ONE of SSN, DL or TAXID will be used if provided, in that order of preference. check_dl_state The two-character postal code for the state the ID was issued in. Leave blank if inappropriate, for instance, when using SSN. check_number An optional check sequence number, provided by the customer. check_routing Checking account routing code. Required for ACH transactions. check_ssn Optional social security number field, but necessary for proper online check fraud screening. In any case, only ONE of SSN, DL or TAXID will be used if provided, in that order of preference. check_taxid Optional tax id number field, but necessary for proper online check fraud screening. In any case, only ONE of SSN, DL or TAXID will be used if provided, in that order of preference. city Customer's shipping city and also the default for b_city. comment1 Additional miscellaneous info to accompany the transaction, up to 4000 characters. country Customer's shipping country and also the default for b_country. email Customer's email address. Required for address verification. fname Customer's first name for shipping and also the default for b_fname. item_desc An optional description of the product or services paid for. Up to 4000 characters. Defaults to a summary of the shopping cart contents. lname Customer's last name for shipping and also the default for b_lname. mv_credit_card_cvv2 Credit Card CVV2 value. This is the three or four digit code on the back of the customer's credit card. Optional, but often will get a lower rate on the transaction. mv_credit_card_exp_month The month of expiration as a two digit number. mv_credit_card_exp_year The year of expiration as a two digit number. This can accept a four digit number in which case the first two digits will be discarded. mv_credit_card_number Credit Card Account Number -- required for Credit Card transactions. mv_order_number The number Interchange assigns to this order. This gets stored as user data in the transaction. This will only come from processed values, not raw values but it does default to the mv_order_number in session space. phone_day Stored as the customer phone number for the transaction and required for address verification. state Customer's shipping state and also the default for b_state. zip Customer's shipping zip and also the default for b_zip. TROUBLESHOOTING
In order to run a test transaction in NetBilling use the testing credit card number set in the Setup/Account Config/Credit Cards section of the NetBilling admin interface. If nothing works: o Make sure you "Require"d the module in interchange.cfg: Require module Vend::Payment::NetBilling o Make sure LWP::UserAgent LWP::Protocol::https and Digest::MD5 are installed and working. You can test to see whether your Perl thinks they are: perl -MLWP::UserAgent -MLWP::Protocol::https -MDigest::MD5 -e 'print "It works "' If it prints "It works." and returns to the prompt you should be OK (presuming they are in working order otherwise). o Check the error logs, both catalog and global. o Make sure you set your payment parameters properly. o Try an order, then put this code in a page: <XMP> [calc] my $string = $Tag->uneval( { ref => $Session->{payment_result} }); $string =~ s/{/{ /; $string =~ s/,/, /g; return $string; [/calc] </XMP> That should show what happened. o If all else fails, consultants are available to help with integration for a fee. BUGS
There is actually nothing *in* Vend::Payment::NetBilling. It changes packages to Vend::Payment and places things there. You cannot randomly pick a transaction ID for NetBilling's Direct Mode. The ID must be assigned from NetBilling. It should either be left blank or a guaranteed unused ID can be retrieved from NetBilling prior to issuing the transaction. This module will overwrite any transaction ID supplied it with the one assigned by NetBilling. AUTHORS
Mark Stosberg <mark@summersault.com>, based on original code by Mike Heins <mike@perusion.com>. Modified from the AuthorizeNet.pm module for NetBilling and later rewritten by Peter Ajamian <peter@pajamian.dhs.org>. CREDITS
Jeff Nappi <brage@cyberhighway.net> Paul Delys <paul@gi.alaska.edu> webmaster@nameastar.net Ray Desjardins <ray@dfwmicrotech.com> Nelson H. Ferrari <nferrari@ccsc.com> SEE ALSO
NetBilling Direct Mode 2.1 documentation is found at: http://netbilling.com/direct/direct2.html perl v5.14.2 2010-03-25 Vend::Payment::NetBilling(3pm)
All times are GMT -4. The time now is 02:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy