Sponsored Content
Top Forums Shell Programming and Scripting Extract XML content from a file Post 302590971 by balajesuri on Wednesday 18th of January 2012 06:05:40 AM
Old 01-18-2012
Code:
#! /usr/bin/perl -w
use strict;

( @ARGV != 1 ) && die "Enter exactly one batch_id. Exiting";
# my @ARGV = ("12345678519"); # Un-comment this line and comment above line if you don't want to give batchid as parameter and want to define in script itself.
my ($f, $x);

open XML, "< input";
for (<XML>) {
    if (/\[<\?xml/../^\]/) {
        if (/\[<\?xml/) { $f=0; s/.*?(\[<\?xml.*)/$1/; $x=$_ }  
        elsif (/<BATCH_ID>$ARGV[0]<\/BATCH_ID>/) { $f=1; print $x; print }
        elsif (!/\[<\?xml/ && !/<BATCH_ID>12345678519<\/BATCH_ID>/ && $f==1) { print }
        elsif ($f==0) { next }
    }
}

Give batch id as parameter to script.
Code:
$ ./test.pl 12345678519
[<?xml version="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED>
<BATCH_ID>12345678519</BATCH_ID>
<UID>3498748823</UID>
<FEED_TYPE>FULL</FEED_TYPE>
<MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME>
<MART_TYPE>SSIA_TRANSACTIONS</MART_TYPE>
<CLIENT_ID>ESPDB</CLIENT_ID>
<SQL>FROM  SSIA_DM_TRANSACTIONS  WHERE   ASAT BETWEEN '2012-01-10T03:44:48.385' and '2012-01-11T03:43:46.646' AND       SSIA_ACCOUNT_CODE = 'BTAC2091' AND PORTF        OLIO_CODE = '02091' </SQL>
</ESP_SSIA_ACC_FEED>
]

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Content extract of a file using awk

Hi Everyone, I have a file with the below content: File1.txt ====== ### ###==> the below table was created for testing1 purpose; ### create table 123 ( field1 date, field2 char(10) primary key(field1) ); ### ###==> the below table was created... (5 Replies)
Discussion started by: nr_shan
5 Replies

2. Shell Programming and Scripting

appending content in a xml file

Please help me on this..... i have a file which has following content: <IPCoreProducerConfig> <Producer> <config> <key>machineId</key> <value>machine1</value> </config> <config> ... (4 Replies)
Discussion started by: Aditya.Gurgaon
4 Replies

3. Shell Programming and Scripting

Extract specific content from a file

My input file: >sequence_1 ASSSSSSSSSSSDDDDDDDDDDDCCCCCCC ASDSFDFFDFDFFWERERERERFSDFESFSFD >sequence_2 ASDFDFDFFDDFFDFDSFDSFDFSDFSDFDSFASDSADSADASD ASDFFDFDFASFASFASFAFSFFSDASFASFASFAFS >sequence_3 VEDFGSDGSDGSDGSDGSDGSDGSDG dDFSDFSDFSDFSDFSDFSDFSDFSDF SDGFDGSFDGSGSDGSDGSDGSDGSDG My... (22 Replies)
Discussion started by: patrick87
22 Replies

4. Shell Programming and Scripting

Need to replace particular content in a xml file

Hi, My requirement is to find a text and replace it with another in a XML file. I am new to Unix,Please provide some suggestion to achieve. Find: <Style ss:ID="ColumnHeader1"> Replace with: <Style ss:ID="ColumnHeader1"> <Borders> <Border ss:Position="Bottom"... (4 Replies)
Discussion started by: cnraja
4 Replies

5. Shell Programming and Scripting

perl extract content of file

I'm using Mail::Internet module, which will basically filter through email content and extract the body of the message my perl script to extract the body of the email #!/usr/bin/perl -w use Mail::Internet; @lines = <STDIN>; $mi_obj = new Mail::Internet(); ... (2 Replies)
Discussion started by: amlife
2 Replies

6. Shell Programming and Scripting

Extract Content from a file

I have an input file with contents like: ./prbru6/12030613.LOG:24514|APPL|prbru6.8269.RTUDaemon.1|?|13:49:56|12/03/06|GMT+3|?|RTUServer Error:Count of Internal Error Qty (-1) < 0, for Audit group id - 1L5XVJ6DQE36AXL, after record number,1, File: EventAuditor.cc, Line: 394|? ... (5 Replies)
Discussion started by: rkrish
5 Replies

7. Shell Programming and Scripting

Create xml file using a content from another xml file

I need to create a xml file(master.xml) with contents from another xml files(children). I have below list of xml files in a temporary location (C:/temp/xmls) 1. child1.xml 2. child2.xml Below is the content of the child1.xml & child2.xml files, child1.xml <root> <emp> ... (3 Replies)
Discussion started by: vel4ever
3 Replies

8. Shell Programming and Scripting

Extract a particular xml only from an xml jar file

Hi..need help on how to extract a particular xml file only from an xml jar file... thanks! (2 Replies)
Discussion started by: qwerty000
2 Replies

9. Shell Programming and Scripting

Extracting content from xml file

Hello All, Hope you are doing well!!!!! I have a small code in the below format in xml file: <UML:ModelElement.taggedValue> <UML:TaggedValue tag="documentation" value="This sequence&#xA;&#xA;HLD_EA_0001X&#xA;HLD_DOORS_002X"/> <UML:TaggedValue tag="documentation" value="This... (11 Replies)
Discussion started by: suvendu4urs
11 Replies

10. UNIX for Dummies Questions & Answers

Grep content in xml file

I have an xml file with header as below. <Provider xmlns="http://www.xyzx.gov/xyz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyzx.gov/xyz xyz.xsd" SCHEMA_VERSION="2.5" PROVIDER="5"> I want to get the schema version here that is 2.5 and put in a... (7 Replies)
Discussion started by: Ariean
7 Replies
xmerl(3erl)						     Erlang Module Definition						       xmerl(3erl)

NAME
xmerl - Functions for exporting XML data to an external format. DESCRIPTION
Functions for exporting XML data to an external format. EXPORTS
callbacks(Module) -> Result Types Module = atom() Result = [atom()] Find the list of inherited callback modules for a given module. export(Content, Callback) -> ExportedFormat Equivalent to export(Data, Callback, []) . export(Content, Callback, RootAttributes) -> ExportedFormat Types Content = [Element] Callback = atom() RootAttributes = [XmlAttributes] Exports normal, well-formed XML content, using the specified callback-module. Element is any of: * #xmlText{} * #xmlElement{} * #xmlPI{} * #xmlComment{} * #xmlDecl{} (See xmerl.hrl for the record definitions.) Text in #xmlText{} elements can be deep lists of characters and/or binaries. RootAttributes is a list of #xmlAttribute{} attributes for the #root# element, which implicitly becomes the parent of the given Con- tent . The tag-handler function for #root# is thus called with the complete exported data of Content . Root attributes can be used to specify e.g. encoding or other metadata of an XML or HTML document. The Callback module should contain hook functions for all tags present in the data structure. A hook function must have the follow- ing format: Tag(Data, Attributes, Parents, E) where E is the corresponding #xmlElement{} , Data is the already-exported contents of E and Attributes is the list of #xmlAt- tribute{} records of E . Finally, Parents is the list of parent nodes of E , on the form [{ParentTag::atom(), ParentPosition::inte- ger()}] . The hook function should return either the data to be exported, or a tuple {'#xml-alias#', NewTag::atom()} , or a tuple {'#xml-rede- fine#', Content} , where Content is a content list (which can be on simple-form; see export_simple/2 for details). A callback module can inherit definitions from other callback modules, through the required function '#xml-interitance#() -> [Modu- leName::atom()] . See also: export/2 , export_simple/3 . export_content(Es::Content, Callbacks) -> term() Types Content = [Element] Callback = [atom()] Exports normal XML content directly, without further context. export_element(E, CB) -> term() Exports a normal XML element directly, without further context. export_element(E, CallbackModule, CallbackState) -> ExportedFormat For on-the-fly exporting during parsing (SAX style) of the XML document. export_simple(Content, Callback) -> ExportedFormat Equivalent to export_simple(Content, Callback, []) . export_simple(Content, Callback, RootAttrs::RootAttributes) -> ExportedFormat Types Content = [Element] Callback = atom() RootAttributes = [XmlAttributes] Exports "simple-form" XML content, using the specified callback-module. Element is any of: * {Tag, Attributes, Content} * {Tag, Content} * Tag * IOString * #xmlText{} * #xmlElement{} * #xmlPI{} * #xmlComment{} * #xmlDecl{} where * Tag = atom() * Attributes = [{Name, Value}] * Name = atom() * Value = IOString | atom() | integer() Normal-form XML elements can thus be included in the simple-form representation. Note that content lists must be flat. An IOString is a (possibly deep) list of characters and/or binaries. RootAttributes is a list of: * XmlAttributes = #xmlAttribute{} See export/3 for details on the callback module and the root attributes. The XML-data is always converted to normal form before being passed to the callback module. See also: export/3 , export_simple/2 . export_simple_content(Content, Callback) -> term() Exports simple XML content directly, without further context. export_simple_element(Content, Callback) -> term() Exports a simple XML element directly, without further context. AUTHORS
<> xmerl 1.2.8 xmerl(3erl)
All times are GMT -4. The time now is 10:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy