Sponsored Content
Top Forums Shell Programming and Scripting Getting string from xml tags using sed and grep Post 303030017 by umen on Monday 4th of February 2019 02:48:50 PM
Old 02-04-2019
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 :
Code:
 <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 extract the string :

<version>mainapp.1.4</version>


i tried this :

Code:
 sed -n '/version/,/version/p' pom.xml | grep -o -e '<version>.*'

but it gives me all the versions

also i try to capture :

Code:
 sed -n '/\/artifactId/,/\/version/p' pom.xml | grep -o -e '<version>.*'

but all file is printed




Code:
  <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" >
    	<modelVersion>55.0.0</modelVersion>
     
    	<parent>
    		<groupId>org.test.proj</groupId>
    		<artifactId>test-invoker</artifactId>
    		<version>invoker.0.4</version>
    	</parent>
    
    	<groupId>org.test.proj.assent</groupId>
    	<artifactId>mainapp</artifactId>
    	<version>mainapp.1.4</version>
    	<packaging>pom</packaging>
    	<name>main app 1</name>
    
    	<properties>
    		<app-name>Testing App</app-name>
    	</properties>
    	
    	<dependencyManagement>
    		<dependencies>
    			<dependency>
    				<groupId>com.prod.db</groupId>
    				<artifactId>srver-db</artifactId>
    				<version>${project.version}</version>
    			</dependency>
    		</dependencies>
    	</dependencyManagement>
    	</project>


i can use only native linux tools no installs
 

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
POM_REMOVE_PLUGIN(7)						Java Packages Tools					      POM_REMOVE_PLUGIN(7)

NAME
pom_remove_plugin - remove Maven plugin invocation from POM file SYNOPSIS
%pom_remove_plugin [groupId]:[artifactId] [POM-location] DESCRIPTION
This macro patches specified POM file not to contain invocations of given Maven plugin. groupId and artifactId are identifiers of Maven group and artifact of the plugin which invocation is to be removed. If they are ommited then all identifiers are matched. POM location can be either a full path to the POM file, or a path to the directory containing pom.xml. If POM location is not given then pom.xml from current working directory is used. EXAMPLES
%pom_remove_plugin maven-shade-plugin - this call removes invocation of Maven Shade Plugin from POM in current working directory. AUTHOR
Written by Mikolaj Izdebski. REPORTING BUGS
Bugs should be reported through Red Hat Bugzilla at http://bugzilla.redhat.com/. SEE ALSO
pom_add_dep(7), pom_add_parent(7), pom_add_plugin(7), pom_disable_module(7), pom_remove_dep(7), pom_remove_parent(7), pom_set_parent(7), pom_xpath_inject(7), pom_xpath_remove(7), pom_xpath_replace(7), pom_xpath_set(7). JAVAPACKAGES
06/10/2014 POM_REMOVE_PLUGIN(7)
All times are GMT -4. The time now is 11:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy