Sponsored Content
Top Forums Shell Programming and Scripting Getting string from xml tags using sed and grep Post 303030021 by bakunin on Monday 4th of February 2019 04:24:14 PM
Old 02-04-2019
Please see why this won't (reliably) work.

In your case you try to discern between <version>.....</version> inside and outside of certain other tags (like "parent" or "dependencyManagement"). This is called "context", so you do a context-oriented search. sed (and even more so grep) are simply not the right tools for this kind of endeavour. Use an XML parser for that, otherwise you always get results that are "more or less correct" - which, with bad circumstances, comes down to "outright wrong".

I hope this helps.

bakunin
This User Gave Thanks to bakunin 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. Shell Programming and Scripting

replace string in XML with sed

Greetings, I have an XML : file.xml <component> <name>abcd</name> <value>1234</value> </component> I am using sed to replace abcd with the desired value dynamically without knowing the actual value. sed 's/<name>./]\{1,\}<\/name>/<name>ijkl<\/name>/' file.xml > newfile.xml I... (6 Replies)
Discussion started by: chiru_h
6 Replies

4. Shell Programming and Scripting

Like grep -v for a string over 2 lines? Sed?

Hi, I have a log file that I need to monitor as it's being written to, and I want to exclude certain strings from the output. At the moment I'm using ... tail -f LogFileName_`date +%d`.log | egrep -v "First String To Exclude | 2nd string | 3rd string" ...which works OK - but now I need to... (1 Reply)
Discussion started by: jake657
1 Replies

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

6. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

7. Shell Programming and Scripting

awk and or sed command to sum the value in repeating tags in a XML

I have a XML in which <Amt Ccy="EUR">3.1</Amt> tag repeats. This is under another tag <Main>. I need to sum all the values of <Amt Ccy=""> (Ccy may vary) coming under <Main> using awk and or sed command. can some help? Sample looks like below <root> <Main> ... (6 Replies)
Discussion started by: bk_12345
6 Replies

8. Shell Programming and Scripting

Search and replace the string with new word using xml tags

Hi All i need to replace the url1 inside <remote> tag in below xml in first instance and in the second instance with url2. any help appreciated <locations> <hudson.scm.SubversionSCM_-ModuleLocation> <remote>https://svn2015.com/svn/repos/internalshard</remote> ... (4 Replies)
Discussion started by: madankumar.t@hp
4 Replies

9. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

10. UNIX for Beginners Questions & Answers

How to fetch the value from a xml using sed, GREP?

I have a simple xml file,need the output with the <value> tag and <result> tag text.xml <test-method status="FAIL" duration="45"> <value> Id=C18 </value> <result> wrong paramter </result> </test-method> <test-method status="FAIL" duration="45"> <value> Id=C19 </value> <result> Data... (5 Replies)
Discussion started by: DevAakash
5 Replies
RDF::Trine::Parser(3pm) 				User Contributed Perl Documentation				   RDF::Trine::Parser(3pm)

NAME
RDF::Trine::Parser - RDF Parser class VERSION
This document describes RDF::Trine::Parser version 1.000 SYNOPSIS
use RDF::Trine::Parser; RDF::Trine::Parser->parse_url_into_model( $url, $model ); my $parser = RDF::Trine::Parser->new( 'turtle' ); $parser->parse_into_model( $base_uri, $rdf, $model ); $parser->parse_file_into_model( $base_uri, 'data.ttl', $model ); DESCRIPTION
RDF::Trine::Parser is a base class for RDF parsers. It may be used as a factory class for constructing parser objects by name or media type with the "new" method, or used to abstract away the logic of choosing a parser based on the media type of RDF content retrieved over the network with the "parse_url_into_model" method. METHODS
"media_type" Returns the canonical media type associated with this parser. "media_types" Returns the media types associated with this parser. "parser_by_media_type ( $media_type )" Returns the parser class appropriate for parsing content of the specified media type. "guess_parser_by_filename ( $filename )" Returns the best-guess parser class to parse a file with the given filename. "new ( $parser_name, @args )" Returns a new RDF::Trine::Parser object for the parser with the specified name (e.g. "rdfxml" or "turtle"). If no parser with the specified name is found, throws a RDF::Trine::Error::ParserError exception. Any @args will be passed through to the format-specific parser constructor. If @args contains the key-value pair "(canonicalize => 1)", literal value canonicalization will be attempted during parsing with warnings being emitted for invalid lexical forms for recognized datatypes. "parse_url_into_model ( $url, $model [, %args] )" Retrieves the content from $url and attempts to parse the resulting RDF into $model using a parser chosen by the associated content media type. If %args contains a 'content_cb' key with a CODE reference value, that callback function will be called after a successful response as: $content_cb->( $url, $content, $http_response_object ) "parse_into_model ( $base_uri, $data, $model [, context => $context] )" Parses the $data, using the given $base_uri. For each RDF statement parsed, will call "$model->add_statement( $statement )". "parse_file_into_model ( $base_uri, $fh, $model [, context => $context] )" Parses all data read from the filehandle or file $fh, using the given $base_uri. For each RDF statement parsed, will call "$model->add_statement( $statement )". "parse_file ( $base_uri, $fh, $handler )" Parses all data read from the filehandle or file $fh, using the given $base_uri. If $fh is a filename, this method can guess the associated parse. For each RDF statement parses $handler is called. "parse ( $base_uri, $rdf, &handler )" "new_bnode_prefix ()" Returns a new prefix to be used in the construction of blank node identifiers. If either Data::UUID or UUID::Tiny are available, they are used to construct a globally unique bnode prefix. Otherwise, an empty string is returned. BUGS
Please report any bugs or feature requests to through the GitHub web interface at <https://github.com/kasei/perlrdf/issues>. AUTHOR
Gregory Todd Williams "<gwilliams@cpan.org>" COPYRIGHT
Copyright (c) 2006-2012 Gregory Todd Williams. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-29 RDF::Trine::Parser(3pm)
All times are GMT -4. The time now is 06:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy