Extract select match value of same contents in XML fileText 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
Paid for article while in US on F1 visa?
Arrow those variables!
Mutually beneficial digestive system symbiotes
How do I gain back my faith in my PhD degree?
Today is the Center
What typically incentivizes a professor to change jobs to a lower ranking university?
Why is 150k or 200k jobs considered good when there's 300k+ births a month?
Important Resources for Dark Age Civilizations?
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
How much of data wrangling is a data scientist's job?
Can the number of solutions to a system of PDEs be bounded using the characteristic variety?
Took a trip to a parallel universe, need help deciphering
Are astronomers waiting to see something in an image from a gravitational lens that they've already seen in an adjacent image?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
if condition in the past
dbcc cleantable batch size explanation
Could gravitational lensing be used to protect a spaceship from a laser?
Is it inappropriate for a student to attend their mentor's dissertation defense?
Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?
Operational amplifier as comparator at high frequency
Why does Kotter return in Welcome Back Kotter?
Were any external disk drives stacked vertically?
How old can references or sources in a thesis be?
Question relative to pads for capacitors - high frequency
Extract select match value of same contents in XML file
Text 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
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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 Mar 27 at 10:17
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 Mar 27 at 10:25
Kusalananda♦Kusalananda
140k17261433
140k17261433
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
-xml, xmlstarlet