Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to insert subnode in xml file using xmlstarlet or any other bash command? Post 303038590 by Sekhar419 on Friday 6th of September 2019 04:26:30 PM
Old 09-06-2019
How to insert subnode in xml file using xmlstarlet or any other bash command?

I have multiple xml files where i want to update a subnode if the subnode project points to different project or insert a subnode if it doesn't exist using a xmlstarlet or any other command that can be used in a bash script.

I have been able to update the subnode project if it doesn't point to the right project using xml starlet command, but i am not able to insert subnode project if the project tag doesn't exist.

I have tried.

Code:
xmlstarlet ed -P --update "///module[@id='pxc110237_1']/@project" -v"X1" --insert"///module[@id='pxc110237_1']/@project --type attr -n style -v"X1" file.xml

The file looks like:
Code:
 <?xml version="1.0"?>
  <kgcontent>
    <containers>
       <module project="ANY" level="1" id="pxc110233_1"/>
       <module project="X1" level="1" id="pxc110234_1"/>
       <module id="pxc110235_1"/>
    </containers>
  <kgcontent>

I want the output to look like:
Code:
<?xml version="1.0"?>
  <kgcontent>
    <containers>
       <module project="ANY" level="1" id="pxc110233_1"/>
       <module project="X1" level="1" id="pxc110234_1"/>
       <module project="X1" id="pxc110235_1"/>
    </containers>
  <kgcontent>

The starlet command i used doesn't have any effect on the file. how can i fix the above problem? any pointers would be great help Smilie

Linux distrubution: SUSE
Shell: Bash

Thank you!
This User Gave Thanks to Sekhar419 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to run shell command and insert results to existing xml file

Hi. Thanks for any help with this. I'm not new to programming but I am new to shell programming. I need a script that will 1. execute 'df -k' and return the volume names with specific text 2. surround each line of the above results in opening and closing xml tags 3. insert the results of step... (5 Replies)
Discussion started by: littlejon
5 Replies

2. Shell Programming and Scripting

xmlstarlet template parse small xml file

I have a file like: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <geonames> <geoname> <toponymName>Palos Verdes</toponymName> <name>Palos Verdes</name> <lat>42.1628912</lat> <lng>-123.6481235</lng> <geonameId>5718340</geonameId> <countryCode>US</countryCode>... (4 Replies)
Discussion started by: unclecameron
4 Replies

3. Shell Programming and Scripting

xmlstarlet parse field from file

I have a xmlfile like this: <?xml version="1.0" encoding="utf-8"?> <contentlocation xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns="http://wherein.yahooapis.com/v1/schema" xml:lang="en"> <processingTime>0.001538</processingTime> ... (1 Reply)
Discussion started by: unclecameron
1 Replies

4. Shell Programming and Scripting

Insert value of env variable in xml file

Hello, I have the following variables set in my env echo $MY_XSD_FILE /home/jak/sample.xsd echo $MY_INTERVAL_VALUE 4 I want to insert them between the xml tags in my xml file cat sample.xml ::::::::::::::: ::::::::::::::: <property name="FILE"></property> :::::::::::::::::::::::... (2 Replies)
Discussion started by: jakSun8
2 Replies

5. Shell Programming and Scripting

Insert a new subnode in a xml file

Hi, i have an xml file and i want to edit a new sub node in a file like val="<activity android:label="@string/app_name" android_name=".MainActivity1" android:launchMode="singleTask" android:screenOrientation="portrait" ... (1 Reply)
Discussion started by: gautamshrm3
1 Replies

6. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

7. Shell Programming and Scripting

awk command to insert a tag in XML

Hi All, I need a help on inserting a XML tag. Actual input <var> <nam>abcd</nam> <a1>.</a1> </var> if tag <a1>.</a1> is getting missed in XML like below <var> <nam>abcd</nam> </var> i need to insert wherever it is missed after <nam> tag and before </var> tag. Could anyone... (3 Replies)
Discussion started by: mohanalakshmi
3 Replies

8. Shell Programming and Scripting

Insert text after match in XML file

Having a little trouble getting this to work just right. I have xml files that i want to split some data. I have 2 <name> tags within the file I would like to take only the first tag and split the data. tag example. From this. TAB<Name>smith, john</Name> to TAB<Name>smith,... (8 Replies)
Discussion started by: whegra
8 Replies

9. UNIX for Beginners Questions & Answers

Bash: Insert in a variable a file

hi all i have a problem in the bash shell. i'd like insert in a variable a file for example : i have a file datafine.log in this file there is : 17/JUN/2019 i want to insert the value of datafine.log in a variable. Regards Frncesco edit by bakunin: please use CODE-tags for your data... (2 Replies)
Discussion started by: Francesco_IT
2 Replies

10. UNIX for Beginners Questions & Answers

How to insert a string and variable at specified position in command in bash?

I currently have a loop that reads all .bam files in a directory (wont always be 4 like in this example, into $id. What I am trying to do, unsucessfully, is create specific new lines in an exsisting command using each $id. Each new line would be: --bam ${id} \ Tried p=$dir... (8 Replies)
Discussion started by: cmccabe
8 Replies
projdel(1M)						  System Administration Commands					       projdel(1M)

NAME
projdel - delete a project from the system SYNOPSIS
projdel [-f filename] project DESCRIPTION
The projdel utility deletes a project from the system and makes the appropriate changes to the system file. OPTIONS
The following options are supported: -f filename Specify the project file to modify. If no filename is specified, the system project file, /etc/project, is modified. OPERANDS
The following operands are supported: project The name of the project to be deleted. EXIT STATUS
The following exit values are returned: 0 Successful completion. 2 The command syntax was invalid. A usage message for projdel is displayed. 3 An invalid argument was provided to an option. 4 The projid given with the -p option is already in use. 5 The project files contain an error. See project(4). 6 The project to be modified, group, user, or resource does not exist. 9 The project is already in use. 10 Cannot update the /etc/project file. FILES
/etc/project System project file ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |Interface stabilty | See below. | +-----------------------------+-----------------------------+ Invocation is evolving. Human readable output is unstable. SEE ALSO
projects(1), groupadd(1M), groupdel(1M), groupmod(1M), grpck(1M), logins(1M), projadd(1M), projmod(1M), useradd(1M), userdel(1M), user- mod(1M), project(4), attributes(5) DIAGNOSTICS
In case of an error, projdel prints an error message and exits with a non-zero status. NOTES
projdel deletes a project definition only on the local system. If a network name service such as NIS or LDAP is being used to supplement the local /etc/project file with additional entries, projdel cannot change information supplied by the network name service. SunOS 5.10 4 May 2004 projdel(1M)
All times are GMT -4. The time now is 02:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy