Questions tagged [xml]

A simple, very flexible text format that stands for eXtensible Markup Language.

Filter by
Sorted by
Tagged with
26 votes
9 answers
163k views

Parse XML to get node value in bash script?

I would like to know how I can get the value of a node with the following paths: config/global/resources/default_setup/connection/host config/global/resources/default_setup/connection/username ...
user avatar
-2 votes
1 answer
57 views

Replace Tag of and xml file after pattern matching using shell

I have an input xml file like below INPUT FILE <ReconSummary> <entryName>Total Deep</entryName> <Code>777</Code> <License>L</License> <Tran>H20</Tran&...
user avatar
4 votes
2 answers
4k views

Insert a multiline string into another string

I need to insert lines into an xml file : Insert <one> </one> into <tags> </tags> To obtain <tags> <one> </one> </tags> I tried this: ...
user avatar
4 votes
3 answers
11k views

Delete XML node containing certain element

I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed: <Placemark> <styleUrl>#m_ylw-pushpin330</...
user avatar
  • 4,452
2 votes
6 answers
2k views

Replacement of XML based on attribute content using sed

I've got to replace some attribute content in an XML tag, depending on a parameter $1. We've got in input, for example: <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="OO ...
user avatar
0 votes
1 answer
786 views

xmllint usage - having a hard time getting xml attributes

I'm in the process of retreiving some data from a xml file, it is actually a SSIS package file (dtsx). I've read about using xmllint, however I'm having a hard time retrieving what I want. I'd like ...
user avatar
  • 3
0 votes
2 answers
72 views

extract all XML tags and values

I have this long line: <hdr><name><first>John</first><mid></mid><last>Smith</last></name><dob>04181995</dob><phone>5550001111<...
user avatar
  • 1
0 votes
5 answers
15k views

How to grep an xml block in an xml file using a keyword in ksh

I have a file Sample.xml which contains a lot of services inside it and the structure looks like this Notes: I cannot use any XML parser tool as I don't have permission, read only My xmllint ...
user avatar
13 votes
6 answers
16k views

Extract an attribute value from XML

Using Bash, File: <?xml version="1.0" encoding="UTF-8"?> <blah> <blah1 path="er" name="andy" remote="origin" branch="master" tag="true" /> <blah1 path="er/er1" name="...
user avatar
  • 133
1 vote
5 answers
856 views

lines to columns with awk

I have to following sample output: <HARDWARE> <NAME>WIN1</NAME> <OS>Windows 7</OS> <IP>1.2.3.4</IP> <DOMAIN>contoso.com</DOMAIN> &...
user avatar
10 votes
2 answers
3k views

Parsing XML, JSON, and newer data file formats in UNIX using command line utilities

The Unix environment has some excellent tools for parsing text in various forms. However, of late, the data is not in the traditional (historical) formats (CSV, TSV, record-based or some other ...
user avatar
  • 181
2 votes
1 answer
8k views

Confused about how to convert XML to CSV using xmlstarlet on OS X?

I asked a question earlier and it was closed as being a duplicate: How to parse XML to CSV with a shell script?. The answer in the duplicate that was linked suggested using a tool called XMLStarlet, ...
user avatar
  • 10.7k
4 votes
1 answer
3k views

How to remove nodes from XML file as command line?

I have an xml file that contains the tag </w:rPr> several times. It is used like this <w:rPr><w:rFonts w:ascii="Symbol" w:hAnsi="Symbol" w:hint="default"/></w:rPr> However ...
user avatar
  • 95
3 votes
1 answer
273 views

Adding Numerical Suffixes to Tag-Names to Distinguish XML Elements

I have an XML file with multiple child elements which have the same tag-name, ex. <Name>Luigi</Name>, <Name>Mario</Name>, <Name>Peach</Name>. Here is a mock-up of ...
user avatar
  • 33
5 votes
2 answers
13k views

How to parse an xml file in a shell script

I would like to know how can I split my data from the following format: <datas> <data> <name>Name1</name> </data> <data> <name>Name2</name> <...
user avatar
  • 53
4 votes
2 answers
2k views

alter a line and remove tag using perl from xml file?

I have an xml file (client_23.xml) in which I need to alter one line and remove one whole tag from it so I came up with perl script: In my xml file, I have a block like this. There will be only one ...
user avatar
4 votes
4 answers
806 views

Extracting sea level pressure from KML using Shell

I'm currently working on a little project; in a kml file called weatherdata.kml, I would like to extract the sea level pressure for each <Placemark> element. I'm trying to parse the information ...
user avatar
3 votes
4 answers
686 views

Remove all <FOLDER> nodes != tag value

I know that xml parsers are the ideal way to go here, but none are available or are able to be added to my environment. Lets take XML which follows the following structure: <CONTAINER> <...
user avatar
3 votes
2 answers
503 views

Shell script to remove child xml tags conditionally

I have a xml file having following content. <contracts> <clients> <client> <name>Nicol</name> <clientRef>123</clientRef> ...
user avatar
  • 151
3 votes
1 answer
125 views

How to rename, in an XML file, specific tags that are embedded in some other specific tags

What is the xmlstarlet command to replace a tag value by another one, only for specified tags embedded in other specified tags? Example: searching every occurance of the tag b, that needs to be ...
user avatar
  • 77
3 votes
4 answers
818 views

sed regex fails to capture the entire paragraph containing the pattern

I have this XML file (example) <This is a line of text with a year=2020 month=12 in it This line of text does not have a year or month in it This year=2021 is the current year the current month=1 ...
user avatar
  • 323
3 votes
5 answers
3k views

Efficient data extraction from multiple files to a single CSV file

I have a large collection of XML files with the same exact structure: $ cat file_<ID>.xml ... ... ... <double>1.2342</double> <double>2.3456</double> ...
user avatar
2 votes
3 answers
702 views

Sorting an XML file in UNIX with a Bash script?

I am trying to sort my XML file that looks like this by alphabetical order. This is a part of a larger bash script so it needs to work within that script: <Module> <Settings> &...
user avatar
2 votes
2 answers
5k views

How to find a text, copy it and insert in next line in a file?

I'm trying to write a script that processes .xml file. It has to find all lines with a <title> element, copy it, and paste in a next line after that found one, but also changing the element ...
user avatar
  • 23
1 vote
4 answers
6k views

How to decode base64 text in xml file in Linux?

I'm new in linux (shell). I need to decode base64 text in xml file using linux shell script. Could you please help me to write linux shell script for decoding the values of those tags where attribute ...
user avatar
1 vote
3 answers
1k views

how to search and replace PATH element with SED of xml file in bash

I would like to replace the current element inside example path tag from: ... <examples> <example path='/test/test123/test12345.txt'/> <examples> ... to ... <examples> <...
user avatar
1 vote
3 answers
272 views

How can XPath functions be expressed to output each input element?

I'm using this command: xmllint --xpath 'substring-after(string(//item/link), "_")' rss.xml And get the desired output, except it's on the first element. How would I fix this to have it be ...
user avatar
  • 139
1 vote
3 answers
2k views

How to comment out contents in xml file using sed?

I am creating a bash script to setup tomcat server. I need to comment some contents from context.xml file. I tried with sed but not able match the contents. Here is full context.xml file: <?xml ...
user avatar
1 vote
1 answer
807 views

Replacing all `&` but not the one in XML entity `&amp;` with `#` with sed in a given XML tag

I needed to replace all & with #, inside and only inside the <faultstring> ... </faultstring> tag. Additionally, the & in &amp; should not be changed. Sample input: 123&&...
user avatar
  • 47
1 vote
4 answers
7k views

Replace an XML attribute's value with the value of a shell variable

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE POWERMART SYSTEM "powrmart.dtd"> <POWERMART CREATION_DATE="12/01/2016 17:43:15" REPOSITORY_VERSION="184.93"> <REPOSITORY NAME="...
user avatar
0 votes
2 answers
713 views

Remove string with > and forward-slash from xml code

I want to remove two strings globally from some xml code. They are: </sellingStatus> and <sellingStatus> I have tried the following unsuccessfully: sed -i 'sed -i 's/</...
user avatar
  • 413
0 votes
1 answer
93 views

Getting syntax error exception for “expr”

I have an xml file which looks like below INPUT XML FILE <ReconSummary> <entryName>Total Deep</entryName> <Code>777</Code> <License>L</License> <Tran>...
user avatar
0 votes
3 answers
1k views

Remove string with spaces and quotes from xml file

I would like to remove the string currencyId="GBP" from an xml file. Please note there is a single space before the first letter c. I am having trouble parsing the data and removing this string ...
user avatar
  • 413
0 votes
2 answers
714 views

remove anything between angle bracket including it [duplicate]

I have a very big text file ~ 105 G it's includes a lot of <XXXX> (angle brackets including text in between). I want to remove those brackets and text in between.
user avatar
  • 223
0 votes
3 answers
62 views

How to replace a matching string if n+2 line does not contain a particular string

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/...
user avatar
0 votes
2 answers
681 views

How to implement awk range pattern in fetching an xml block when the input parameter is in the middle of the block

I am trying to fetch an xml block like this: <machine name="sample1" min="1" max="10" idleTime="300" backend="ABC,XYZ"> <handler className="com.abc.xyz.qwerty.foo.FooBar" /&...
user avatar
0 votes
6 answers
544 views

From gpx to csv file

<wpt lat="1.345529841" lon="103.7577152"><time>2010-01-01T00:00:00Z</time</wpt> <wpt lat="1.345529841" lon="103.7577152"><time>2010-01-01T00:00:00Z</time></...
user avatar
  • 357
0 votes
1 answer
9k views

How to parse XML to CSV with a shell script? [closed]

What is the ideal way to parse an .xml file into a .csv file that I could include with my shell scripts. I know bash can't do it but I'm unsure if I should try in awk or sed. I imagine a language ...
user avatar
0 votes
3 answers
2k views

How can I escape special characters in a sed "sub-command"?

I'm using xmllint --shell on a large XML file, and using the write command to write out an XML snippet to be used in testing. The snippet that gets written out needs a couple of lines from the ...
user avatar
  • 1,746
0 votes
4 answers
866 views

Find xml tag and replace the text inside the tag to a parameter value multiple occurrences

Find a specific xml tag and replace the text inside tags to some parameterized value. Multiple occurrences need to be replaced. Sample file content: <a>abc</a> Current attempt: sed -i &...
user avatar
-1 votes
2 answers
57 views

sed command succesfuly find and replace in file , bit erasing everything in the new file

i have this xml text in file named test2.txt <This is a line of text with a year=2020 month=12 in it This line of text does not have a year or month in it This year=2021 is the current year the ...
user avatar
  • 323