Find the value between two ranges in xml file of one particular tag

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have xml file where having tags <a>0000123</a>, <a>1200000</a>, <a>0001000</a>.
I need to get only the value which this particular tag should be between 100 to 1000.
xml
add a comment |Â
up vote
0
down vote
favorite
I have xml file where having tags <a>0000123</a>, <a>1200000</a>, <a>0001000</a>.
I need to get only the value which this particular tag should be between 100 to 1000.
xml
tag will be in format of <a>0000123</a>
â Ugan
Feb 27 at 13:32
So the tags areatags (allatags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
â Kusalananda
Feb 27 at 13:33
1
Please edit your question and add a xml example
â ChristophS
Feb 27 at 13:36
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have xml file where having tags <a>0000123</a>, <a>1200000</a>, <a>0001000</a>.
I need to get only the value which this particular tag should be between 100 to 1000.
xml
I have xml file where having tags <a>0000123</a>, <a>1200000</a>, <a>0001000</a>.
I need to get only the value which this particular tag should be between 100 to 1000.
xml
edited Feb 27 at 13:46
Kusalananda
103k13202318
103k13202318
asked Feb 27 at 13:32
Ugan
1
1
tag will be in format of <a>0000123</a>
â Ugan
Feb 27 at 13:32
So the tags areatags (allatags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
â Kusalananda
Feb 27 at 13:33
1
Please edit your question and add a xml example
â ChristophS
Feb 27 at 13:36
add a comment |Â
tag will be in format of <a>0000123</a>
â Ugan
Feb 27 at 13:32
So the tags areatags (allatags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?
â Kusalananda
Feb 27 at 13:33
1
Please edit your question and add a xml example
â ChristophS
Feb 27 at 13:36
tag will be in format of <a>0000123</a>
â Ugan
Feb 27 at 13:32
tag will be in format of <a>0000123</a>
â Ugan
Feb 27 at 13:32
So the tags are
a tags (all a tags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?â Kusalananda
Feb 27 at 13:33
So the tags are
a tags (all a tags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?â Kusalananda
Feb 27 at 13:33
1
1
Please edit your question and add a xml example
â ChristophS
Feb 27 at 13:36
Please edit your question and add a xml example
â ChristophS
Feb 27 at 13:36
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
Using XMLStarlet:
xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.
On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.
Example:
$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>
$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123
In my case (kubuntu 17.10, bash) the command of the xmlstarlet package isxmlstarletinstead ofxml. Works like a charme and does not look too complicated ;)
â ChristophS
Feb 27 at 15:09
add a comment |Â
up vote
1
down vote
With xmllint :
xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml
If you want to separate with newlines :
xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'
AFAIK, it's a limitation of using xmllint without the switch --shell
How do you separate the result? for example by nl or whitespace ...
â ChristophS
Feb 27 at 14:55
Check my edited post
â Gilles Quenot
Feb 27 at 15:01
1
As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/â¦). Great answer anyway!
â ChristophS
Feb 27 at 15:04
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Using XMLStarlet:
xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.
On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.
Example:
$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>
$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123
In my case (kubuntu 17.10, bash) the command of the xmlstarlet package isxmlstarletinstead ofxml. Works like a charme and does not look too complicated ;)
â ChristophS
Feb 27 at 15:09
add a comment |Â
up vote
1
down vote
Using XMLStarlet:
xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.
On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.
Example:
$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>
$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123
In my case (kubuntu 17.10, bash) the command of the xmlstarlet package isxmlstarletinstead ofxml. Works like a charme and does not look too complicated ;)
â ChristophS
Feb 27 at 15:09
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Using XMLStarlet:
xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.
On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.
Example:
$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>
$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123
Using XMLStarlet:
xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
This will return a list of values between 100 and 1000. These values will be taken from the values of the a nodes of the XML document in file.xml, regardless of where these appear. Zero-filled numbers seems to be handled properly. The -nl at the end ensures that the output's last line has a newline at the end.
On some systems, XMLStarlet is installed as xmlstarlet instead of just xml.
Example:
$ cat file.xml
<?xml version="1.0"?>
<root>
<a>0000123</a>
<a>1200000</a>
<a>0001000</a>
</root>
$ xml sel -t -v '//a[. > 100 and . < 1000]' -nl file.xml
0000123
edited Feb 27 at 13:51
answered Feb 27 at 13:40
Kusalananda
103k13202318
103k13202318
In my case (kubuntu 17.10, bash) the command of the xmlstarlet package isxmlstarletinstead ofxml. Works like a charme and does not look too complicated ;)
â ChristophS
Feb 27 at 15:09
add a comment |Â
In my case (kubuntu 17.10, bash) the command of the xmlstarlet package isxmlstarletinstead ofxml. Works like a charme and does not look too complicated ;)
â ChristophS
Feb 27 at 15:09
In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is
xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)â ChristophS
Feb 27 at 15:09
In my case (kubuntu 17.10, bash) the command of the xmlstarlet package is
xmlstarlet instead of xml. Works like a charme and does not look too complicated ;)â ChristophS
Feb 27 at 15:09
add a comment |Â
up vote
1
down vote
With xmllint :
xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml
If you want to separate with newlines :
xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'
AFAIK, it's a limitation of using xmllint without the switch --shell
How do you separate the result? for example by nl or whitespace ...
â ChristophS
Feb 27 at 14:55
Check my edited post
â Gilles Quenot
Feb 27 at 15:01
1
As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/â¦). Great answer anyway!
â ChristophS
Feb 27 at 15:04
add a comment |Â
up vote
1
down vote
With xmllint :
xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml
If you want to separate with newlines :
xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'
AFAIK, it's a limitation of using xmllint without the switch --shell
How do you separate the result? for example by nl or whitespace ...
â ChristophS
Feb 27 at 14:55
Check my edited post
â Gilles Quenot
Feb 27 at 15:01
1
As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/â¦). Great answer anyway!
â ChristophS
Feb 27 at 15:04
add a comment |Â
up vote
1
down vote
up vote
1
down vote
With xmllint :
xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml
If you want to separate with newlines :
xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'
AFAIK, it's a limitation of using xmllint without the switch --shell
With xmllint :
xmllint --xpath '//a[text() > 100 and text() < 1000]/text()' file.xml
If you want to separate with newlines :
xmllint --shell file.xml <<< 'xpath //a[text() > 100 and text() < 000]/text()' |
grep -oP 'content=K.*'
AFAIK, it's a limitation of using xmllint without the switch --shell
edited Feb 27 at 15:01
answered Feb 27 at 14:36
Gilles Quenot
15.3k13448
15.3k13448
How do you separate the result? for example by nl or whitespace ...
â ChristophS
Feb 27 at 14:55
Check my edited post
â Gilles Quenot
Feb 27 at 15:01
1
As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/â¦). Great answer anyway!
â ChristophS
Feb 27 at 15:04
add a comment |Â
How do you separate the result? for example by nl or whitespace ...
â ChristophS
Feb 27 at 14:55
Check my edited post
â Gilles Quenot
Feb 27 at 15:01
1
As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/â¦). Great answer anyway!
â ChristophS
Feb 27 at 15:04
How do you separate the result? for example by nl or whitespace ...
â ChristophS
Feb 27 at 14:55
How do you separate the result? for example by nl or whitespace ...
â ChristophS
Feb 27 at 14:55
Check my edited post
â Gilles Quenot
Feb 27 at 15:01
Check my edited post
â Gilles Quenot
Feb 27 at 15:01
1
1
As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/â¦). Great answer anyway!
â ChristophS
Feb 27 at 15:04
As far as I could figure out, the output (without visual) separation is a correct xpath expression. A XSLT transformation could be the solution (compgroups.net/comp.text.xml/â¦). Great answer anyway!
â ChristophS
Feb 27 at 15:04
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426939%2ffind-the-value-between-two-ranges-in-xml-file-of-one-particular-tag%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
tag will be in format of <a>0000123</a>
â Ugan
Feb 27 at 13:32
So the tags are
atags (allatags?) and their values is what you want to find? Do you want copies of those tags or do you just need the actual values?â Kusalananda
Feb 27 at 13:33
1
Please edit your question and add a xml example
â ChristophS
Feb 27 at 13:36