Sponsored Content
Top Forums Shell Programming and Scripting Extract strings within XML file between different delimiters Post 302602901 by bab@faa on Tuesday 28th of February 2012 04:10:32 PM
Old 02-28-2012
Extract strings within XML file between different delimiters

Good afternoon!

I have an XML file from which I want to extract only certain elements contained within each line. The problem is that the format of each line is not exactly the same (though similiar). For example, oa_var will be in each line, however, there may be no value or other variables present in some lines (but not others).

So, given the example lines below:
<ex1 oa_var="some_var_name1">val1</ex1>
<ex2 oa_var="some_var_name2" abc="dont_care">val2</ex2>
<ex3 oa_var="some_var_name3" />
<ex4 oa_var="some_var_name4">val4</ex4>
I want to only extract the bolded items (note ex3 doesn't have a value).
some_var_name1 val1
some_var_name2 val2
some_var_name3
some_var_name4 val4
I am open to using shell | awk | sed | perl | python (in that order).
 

10 More Discussions You Might Find Interesting

1. Solaris

To extract everything between two delimiters

My input file looks like " @$SCRIPT/atp_asrmt_adj.sql $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1005w.pls $SCRIPT/dba2000.scr -s / @$SCRIPT/cim1006w.pls start $SCRIPT/cim1020d.sql;^M spool $DATA/cim1021m.sql @$DATA/cim1021m.sql ! rm $DATA/cim1021m.sql spool $DATA/cim1021m.sql... (1 Reply)
Discussion started by: dowsed4u8
1 Replies

2. Programming

c program to extract text between two delimiters from some text file

needa c program to extract text between two delimiters from some text file. and then storing them in to diffrent variables ? text file like 0: abc.txt ========= aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass aaaaaa|11111111|sssssssssss|333333|ddddddddd|34343454564|asass... (7 Replies)
Discussion started by: kukretiabhi13
7 Replies

3. UNIX for Dummies Questions & Answers

Hiding database connection strings from xml file

Hi , I have a configuration file with the following structure: <CONFIG> <DEFAULTS operator="oraread"> <PROPERTY name="hostname" value="myhostname"/> <PROPERTY name="port" value="12343"/> <PROPERTY name="dbname" value="dbname"/> <PROPERTY... (0 Replies)
Discussion started by: neeto
0 Replies

4. Shell Programming and Scripting

Extract strings from file - Help

Hi, I have a file say with following lines (the lines could start from any column and there can be many many create statements in the file) create table table1....table definition... insert into table1 values..... create or replace view view1....view definition.... What i want is to... (2 Replies)
Discussion started by: whoami191
2 Replies

5. Shell Programming and Scripting

Extract two strings from a file and create a new file with these strings

I have the following lines in a log file. It would be great if some one can help me to create a new file with the just entries in the below format. 66.150.161.195 HPSAC=Z05 66.150.161.196 HPSAC=A05 That is just extract the IP address and the string DPSAC=its value 66.150.161.195 -... (1 Reply)
Discussion started by: Tuxidow
1 Replies

6. 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

7. Shell Programming and Scripting

Replace the .txt file between two strings in XML file

Hi i am having XML file with many number of lines,I need to replace between two strings with .txt file using awk. For ex <PersonInfoShipTo ------------------------------ /> My requirement is to replace the content between <PersonInfoShipTo ------------------------------ /> help me. Thanks... (9 Replies)
Discussion started by: Padmanabhan
9 Replies

8. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

9. Shell Programming and Scripting

Extract a value from an xml file

I have this XML file format and all in one line: Fri Dec 23 00:14:52 2016 Logged Message:689|<?xml version="1.0" encoding="UTF-8"?><PORT_RESPONSE><HEADER><ORIGINATOR>XMG</ORIGINATOR><DESTINAT... (16 Replies)
Discussion started by: mrn6430
16 Replies

10. Shell Programming and Scripting

--Parsing out strings for repeating delimiters for everyline

Hello: I have some text output, on SunOS 5.11 platform using KSH: I am trying to parse out each string within the () for each line. I tried, as example: perl -lanF"" -e 'print "$F $F $F $F $F $F"' But for some reason, the output gets all garbled after the the first fields.... (8 Replies)
Discussion started by: gilgamesh
8 Replies
GraphViz::XML(3pm)					User Contributed Perl Documentation					GraphViz::XML(3pm)

NAME
GraphViz::XML - Visualise XML as a tree SYNOPSIS
use GraphViz::XML; my $graph = GraphViz::XML->new($xml); print $g->as_png; DESCRIPTION
This module makes it easy to visualise XML as a tree. XML is hard for humans to grasp, especially if the XML is computer-generated. This modules aims to visualise the XML as a graph in order to make the structure of the XML clear and to aid in understanding the XML. XML elements are represented as diamond nodes, with links to elements within them. Character data is represented in round nodes. Note that the XML::Twig module should be installed. METHODS
new This is the constructor. It takes one mandatory argument, which is the XML to be visualised. A GraphViz object is returned. my $graph = GraphViz::XML->new($xml); as_* The XML can be visualised in a number of different graphical formats. Methods include as_ps, as_hpgl, as_pcl, as_mif, as_pic, as_gd, as_gd2, as_gif, as_jpeg, as_png, as_wbmp, as_ismap, as_imap, as_vrml, as_vtx, as_mp, as_fig, as_svg. See the GraphViz documentation for more information. The two most common methods are: # Print out a PNG-format file print $g->as_png; # Print out a PostScript-format file print $g->as_ps; BUGS
GraphViz tends to reorder the nodes. I hope to find a work around soon (possibly with ports). AUTHOR
Leon Brocard <acme@astray.com> COPYRIGHT
Copyright (C) 2001, Leon Brocard This module is free software; you can redistribute it or modify it under the same terms as Perl itself. perl v5.14.2 2012-04-02 GraphViz::XML(3pm)
All times are GMT -4. The time now is 11:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy