Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to fetch the value from a xml using sed, GREP? Post 303035101 by nezabudka on Tuesday 14th of May 2019 04:43:09 PM
Old 05-14-2019
Code:
sed -n '/<value>\|<result>/ {n;p}' file

--- Post updated at 23:34 ---

Code:
awk '/<value>/ {getline tmp}; /<result>/ {getline; print tmp,$0}' file

--- Post updated at 23:38 ---

Code:
sed -n '/<value>/ {n;h}; /<result>/ {n;H;x;s/\n/ /;p}' file

--- Post updated at 23:43 ---

Code:
sed -n '/<value>/ {n;h}; /<result>/! b; n;H;x;s/\n/ /p' file

These 2 Users Gave Thanks to nezabudka For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep xml tags

Hi I want to get the value between to XML tags as follows <EAN>12345</EAN> so i would want to return 12345. i have tried sed and awk but can't do it. can anyone help? (9 Replies)
Discussion started by: handak9
9 Replies

2. Shell Programming and Scripting

Grep XML tags

I want to search the below XML pattern in the XML files, but the XML files would be in a .GZ files, <PRODID>LCTO84876</PRODID> <PARTNUMBER>8872AC1</PARTNUMBER> <WWPRODID>MODEL84876</WWPRODID> <COUNTRY>US</COUNTRY> <LANGUAGE>1</LANGUAGE> What's the command/script to search it ? :confused: (2 Replies)
Discussion started by: saravvij
2 Replies

3. UNIX for Dummies Questions & Answers

Problems with grep and XML

I'm trying to use grep on XML files. The same grep expressions work on plaint text files but not on XML files (which of course are plain text files). Actually, these expressions work on XML files saved in DreamWeaver, but not when the same files are saved in XML Spy. I want grep to treat these... (4 Replies)
Discussion started by: pauljohn
4 Replies

4. Shell Programming and Scripting

get rid of xml comment by grep or sed

Hi, I would like to get rid of all comment in an xml file by grep or sed command: The content seem like this: <!-- ab cd ef gh ij kl --> Anyone can help? Thanks and Regards (3 Replies)
Discussion started by: RonLii
3 Replies

5. Shell Programming and Scripting

Grep and fetch subsequent lines also

Hi, I need to grep a pattern and fetch subsequent lines till end of the data-set. E.g., i have a file like: AA 1111 23 34 BB 45 56 78 CC 22 44 AA 2222 78 34 56 BB 22 56 67 68 23 CC 56 78 DD 33 55 77 AA 3333 46 BB 58 79 In above file i have 3-data sets where each set starts with... (6 Replies)
Discussion started by: prvnrk
6 Replies

6. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

7. UNIX for Dummies Questions & Answers

GREP for a tag in XML File

I have 2 XML Data files with a tag named PARTICIPATION_TYPE and i am trying to grep for that and getting unique values. However one of the xml data file data is not aligned properly like below. File 1: (works fine when i do grep) grep "PARTICIPATION_TYPE" file1.xml | sort -u Data: ....... (3 Replies)
Discussion started by: Ariean
3 Replies

8. Shell Programming and Scripting

How to grep for a word in xml?

Hi, I have the below tag/s in my xml. <foreign-server name="MOHTASHIM_SERVER"> What will be the easist way to extract MOHTASHIM_SERVER without the double quotes "" from the above tag? Desired Output: (10 Replies)
Discussion started by: mohtashims
10 Replies

9. Shell Programming and Scripting

Getting string from xml tags using sed and grep

how to get string from tags using sed and grep i try to capture the tags : <groupId>org.test.proj.assent</groupId> <artifactId>mainapp</artifactId> <version>mainapp.1.4</version> <packaging>pom</packaging> <name>main app 1</name> and then from there i guess i will... (7 Replies)
Discussion started by: umen
7 Replies

10. Shell Programming and Scripting

Grep to fetch exact list

Hi I have below lists of files filename-1.0.0.tar.gz filename-1.0.1.345657676.snapshots.tar.gz so when I do grep -o 'filename-*.tar.gz' | sort | tail -1 then it consider snapshots as a part of it's result. How can I make sure, that it should only display the results from... (3 Replies)
Discussion started by: manas_ranjan
3 Replies
MKDoc::XML::Stripper(3pm)				User Contributed Perl Documentation				 MKDoc::XML::Stripper(3pm)

NAME
MKDoc::XML::Stripper - Remove unwanted XML / XHTML tags and attributes SYNOPSIS
use MKDoc::XML::Stripper; my $stripper = new MKDoc::XML::Stripper; $stripper->allow (qw /p class id/); my $ugly = '<p class="para" style="color:red">Hello, <strong>World</strong>!</p>'; my $neat = $stripper->process_data ($ugly); print $neat; Should print: <p class="para">Hello, World!</p> SUMMARY
MKDoc::XML::Stripper is a class which lets you specify a set of tags and attributes which you want to allow, and then cheekily strip any XML of unwanted tags and attributes. In MKDoc, this is used so that editors use structural XHTML rather than presentational tags, i.e. strip anything which looks like a <font> tag, a 'style' attribute or other tags which would break separation of structure from content. DISCLAIMER
This module does low level XML manipulation. It will somehow parse even broken XML and try to do something with it. Do not use it unless you know what you're doing. API
my $stripper = MKDoc::XML::Stripper->new() Instantiates a new MKDoc::XML::Stripper object. $stripper->load_def ($def_name); Loads a definition located somewhere in @INC under MKDoc/XML/Stripper. Available definitions are: xhtml10frameset xhtml10strict xhtml10transitional mkdoc16 - MKDoc 1.6. XHTML structural markup You can also load your own definition file, for instance: $stripper->load_def ('my_def.txt'); Definitions are simple text files as follows: # allow p with 'class' and id p class p id # allow more stuff td class td id td style # etc... $stripper->allow ($tag, @attributes) Allows "<$tag>" to appear in the stripped XML. Additionally, allows @attributes to appear as attributes of <$tag>, so for instance: $stripper->allow ('p', 'class', 'id'); Will allow the following: <p> <p class="foo"> <p id="bar"> <p class="foo" id="bar"> However any extra attributes will be stripped, i.e. <p class="foo" id="bar" style="font-color: red"> Will be rewritten as <p class="foo" id="bar"> $stripper->disallow ($tag) Explicitly disallows a tag and all its associated attributes. By default everything is disallowed. $stripper->process_data ($some_xml); Strips $some_xml according to the rules that were given with the allow() and disallow() methods and returns the result. Does not modify $some_xml in place. $stripper->process_file ('/an/xml/file.xml'); Strips '/an/xml/file.xml' according to the rules that were given with the allow() and disallow() methods and returns the result. Does not modify '/an/xml/file.xml' in place. NOTES
MKDoc::XML::Stripper does not really parse the XML file you're giving to it nor does it care if the XML is well-formed or not. It uses MKDoc::XML::Tokenizer to turn the XML / XHTML file into a series of MKDoc::XML::Token objects and strictly operates on a list of tokens. For this same reason MKDoc::XML::Stripper does not support namespaces. AUTHOR
Copyright 2003 - MKDoc Holdings Ltd. Author: Jean-Michel Hiver This module is free software and is distributed under the same license as Perl itself. Use it at your own risk. SEE ALSO
MKDoc::XML::Tokenizer MKDoc::XML::Token perl v5.10.1 2004-10-06 MKDoc::XML::Stripper(3pm)
All times are GMT -4. The time now is 12:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy