Extract select match value of same contents in XML file The Next CEO of Stack OverflowText processing: convert text of table of content into djvu bookmark format?Clean up concatenated XML filesHow to remove a line from a tag in shell script?Extract value from XMLGrep only those lines with “<active>…</active>” whose next line contains specific tag and valueextract xml tag value from the file to Variableneed to join only certain lines of a xml file togetherExtract value from XML file using shell scriptSED remove spaces and line breaksHow to extract selected value in XML
How to start emacs in "nothing" mode (`fundamental-mode`)
How do I construct this japanese bowl?
How easy is it to start Magic from scratch?
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
How should I support this large drywall patch?
How to count occurrences of text in a file?
How did people program for Consoles with multiple CPUs?
Describing a person. What needs to be mentioned?
The King's new dress
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
Science fiction (dystopian) short story set after WWIII
Can the Reverse Gravity spell affect the Meteor Swarm spell?
What is the purpose of the Evocation wizard's Potent Cantrip feature?
MAZDA 3 2006 (UK) - poor acceleration then takes off at 3250 revs
Is HostGator storing my password in plaintext?
Only print output after finding pattern
What makes a siege story/plot interesting?
How do spells that require an ability check vs. the caster's spell save DC work?
What is the difference between "behavior" and "behaviour"?
How long to clear the 'suck zone' of a turbofan after start is initiated?
Why here is plural "We went to the movies last night."
How to be diplomatic in refusing to write code that breaches the privacy of our users
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Text adventure game code
Extract select match value of same contents in XML file
The Next CEO of Stack OverflowText processing: convert text of table of content into djvu bookmark format?Clean up concatenated XML filesHow to remove a line from a tag in shell script?Extract value from XMLGrep only those lines with “<active>…</active>” whose next line contains specific tag and valueextract xml tag value from the file to Variableneed to join only certain lines of a xml file togetherExtract value from XML file using shell scriptSED remove spaces and line breaksHow to extract selected value in XML
I using this command for below xml file.
xmlstarlet sel -t -v '//channel[protected = "True"]/playlist_url' -nl file.xml
and result;
host.net/aa/vodpr
host.net/aa/vodpr/con_tv_r.php
Can I choose a line in result? Example only last line or 2. line?
<?xml version="1.0" encoding="UTF-8" ?>
<items>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/15_info/]]></playlist_url>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/16_info/]]></playlist_url>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/vodpr/]]></playlist_url>
<protected>True</protected>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/vodpr/con_tv_r.php]]></playlist_url>
<protected>True</protected>
</channel>
</items>
xml xmlstarlet
add a comment |
I using this command for below xml file.
xmlstarlet sel -t -v '//channel[protected = "True"]/playlist_url' -nl file.xml
and result;
host.net/aa/vodpr
host.net/aa/vodpr/con_tv_r.php
Can I choose a line in result? Example only last line or 2. line?
<?xml version="1.0" encoding="UTF-8" ?>
<items>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/15_info/]]></playlist_url>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/16_info/]]></playlist_url>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/vodpr/]]></playlist_url>
<protected>True</protected>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/vodpr/con_tv_r.php]]></playlist_url>
<protected>True</protected>
</channel>
</items>
xml xmlstarlet
add a comment |
I using this command for below xml file.
xmlstarlet sel -t -v '//channel[protected = "True"]/playlist_url' -nl file.xml
and result;
host.net/aa/vodpr
host.net/aa/vodpr/con_tv_r.php
Can I choose a line in result? Example only last line or 2. line?
<?xml version="1.0" encoding="UTF-8" ?>
<items>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/15_info/]]></playlist_url>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/16_info/]]></playlist_url>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/vodpr/]]></playlist_url>
<protected>True</protected>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/vodpr/con_tv_r.php]]></playlist_url>
<protected>True</protected>
</channel>
</items>
xml xmlstarlet
I using this command for below xml file.
xmlstarlet sel -t -v '//channel[protected = "True"]/playlist_url' -nl file.xml
and result;
host.net/aa/vodpr
host.net/aa/vodpr/con_tv_r.php
Can I choose a line in result? Example only last line or 2. line?
<?xml version="1.0" encoding="UTF-8" ?>
<items>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/15_info/]]></playlist_url>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/16_info/]]></playlist_url>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/vodpr/]]></playlist_url>
<protected>True</protected>
</channel>
<channel>
<title><![CDATA[*** variable text ***]]></title>
<playlist_url><![CDATA[http://host.net/aa/vodpr/con_tv_r.php]]></playlist_url>
<protected>True</protected>
</channel>
</items>
xml xmlstarlet
xml xmlstarlet
asked yesterday
Ali Haydar DoğanAli Haydar Doğan
62
62
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
To select the playlist_url
value from the channel
node by position in the list, use position()
and compare with some positive integer:
$ xmlstarlet sel -t -v '//channel[position() = 4]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
(in this case, you could use just [4]
in place of [position() = 4]
).
$ xmlstarlet sel -t -v '//channel[position() > 2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the last two from a list of unknown length, combine the test with last()
:
$ xmlstarlet sel -t -v '//channel[position() >= last() - 1]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the second "protected" URL:
$ xmlstarlet sel -t -v '//channel[protected = "True"][2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508934%2fextract-select-match-value-of-same-contents-in-xml-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To select the playlist_url
value from the channel
node by position in the list, use position()
and compare with some positive integer:
$ xmlstarlet sel -t -v '//channel[position() = 4]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
(in this case, you could use just [4]
in place of [position() = 4]
).
$ xmlstarlet sel -t -v '//channel[position() > 2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the last two from a list of unknown length, combine the test with last()
:
$ xmlstarlet sel -t -v '//channel[position() >= last() - 1]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the second "protected" URL:
$ xmlstarlet sel -t -v '//channel[protected = "True"][2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
add a comment |
To select the playlist_url
value from the channel
node by position in the list, use position()
and compare with some positive integer:
$ xmlstarlet sel -t -v '//channel[position() = 4]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
(in this case, you could use just [4]
in place of [position() = 4]
).
$ xmlstarlet sel -t -v '//channel[position() > 2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the last two from a list of unknown length, combine the test with last()
:
$ xmlstarlet sel -t -v '//channel[position() >= last() - 1]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the second "protected" URL:
$ xmlstarlet sel -t -v '//channel[protected = "True"][2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
add a comment |
To select the playlist_url
value from the channel
node by position in the list, use position()
and compare with some positive integer:
$ xmlstarlet sel -t -v '//channel[position() = 4]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
(in this case, you could use just [4]
in place of [position() = 4]
).
$ xmlstarlet sel -t -v '//channel[position() > 2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the last two from a list of unknown length, combine the test with last()
:
$ xmlstarlet sel -t -v '//channel[position() >= last() - 1]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the second "protected" URL:
$ xmlstarlet sel -t -v '//channel[protected = "True"][2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
To select the playlist_url
value from the channel
node by position in the list, use position()
and compare with some positive integer:
$ xmlstarlet sel -t -v '//channel[position() = 4]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
(in this case, you could use just [4]
in place of [position() = 4]
).
$ xmlstarlet sel -t -v '//channel[position() > 2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the last two from a list of unknown length, combine the test with last()
:
$ xmlstarlet sel -t -v '//channel[position() >= last() - 1]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/
http://host.net/aa/vodpr/con_tv_r.php
To get the second "protected" URL:
$ xmlstarlet sel -t -v '//channel[protected = "True"][2]/playlist_url' -nl file.xml
http://host.net/aa/vodpr/con_tv_r.php
answered yesterday
Kusalananda♦Kusalananda
138k17258426
138k17258426
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508934%2fextract-select-match-value-of-same-contents-in-xml-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown