Quantcast
Channel: Parse XML to get node value in bash script? - Unix & Linux Stack Exchange
Browsing latest articles
Browse All 10 View Live

Answer by Dag Wieers for Parse XML to get node value in bash script?

Using xmllint and the --xpath option, it is very easy. You can simply do this: XML_FILE=/path/to/file.xml HOST=$(xmllint --xpath 'string(/config/global/resources/default_setup/connection/host)'...

View Article



Answer by bahamat for Parse XML to get node value in bash script?

Although there are a lot of answers already, I'll chime in with xml2. $ xml2 < test.xml /config/global/install/date=Tue, 11 Dec 2012 12:31:25 +0000...

View Article

Answer by paoul for Parse XML to get node value in bash script?

Using bash and xmllint (as given by the tags): xmllint --version # xmllint: using libxml version 20703 # Note: Newer versions of libxml / xmllint have a --xpath option which # makes it possible to use...

View Article

Answer by manatwork for Parse XML to get node value in bash script?

A pure bash function, just for the unfortunate case when you are not allowed to install anything appropriate. This may, and probably will, fail on more complicated XML: function xmlpath() { local...

View Article

Answer by Bimal Poudel for Parse XML to get node value in bash script?

You can make use of php command line interface coding in bash scripts to handle several complex scripts that actually span over multiple lines of coding. First, try to make your solution using PHP...

View Article


Answer by Charles Duffy for Parse XML to get node value in bash script?

The following works when run against your test data: { read -r host; read -r username; read -r password; read -r dbname; } \ < <(xmlstarlet sel -t -m...

View Article

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

View Article

Answer by KuLuSz for Parse XML to get node value in bash script?

This comment use only sh/bash commands and methods ! /test.xml is your XML type file at first question...#!/bin/sh cat /test.xml | while read line;do [ "$(echo "$line" | grep "<host>")"...

View Article


Answer by Kusalananda for Parse XML to get node value in bash script?

Using xq (from https://kislyuk.github.io/yq/) to just get those strings out:#!/bin/shset -- \ config/global/resources/default_setup/connection/host \...

View Article


Answer by jubilatious1 for Parse XML to get node value in bash script?

Using Raku (formerly known as Perl_6):I recognize the OP requested a bash script, but since other answers have deviated from this requirement, here's a Raku solution (4 one-liners):raku -MXML -e 'my...

View Article
Browsing latest articles
Browse All 10 View Live




Latest Images