Placing the last line first in each html with sedUse sed to print from the very first line until the line containing the last occurrence of a pattern?sed html parsingReplace only on the first matching line with sedHow to append the first line at the end of each line of a file with Sed?Deleting the second to last character in each line - with sedEdit HTML files from the command linedf -h command output in HTML format with specific columnsSed placing text after a certain linesed to insert a html values in a specific line numberUse sed to encapsulate the first word of each paragraph with <i> </i>?
Processor speed limited at 0.4 Ghz
What are the G forces leaving Earth orbit?
How to aggregate categorical data in R?
How does a dynamic QR code work?
How could sorcerers who are able to produce/manipulate almost all forms of energy communicate over large distances?
How dangerous is XSS
Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?
Is it possible to create a QR code using text?
Did 'Cinema Songs' exist during Hiranyakshipu's time?
In the UK, is it possible to get a referendum by a court decision?
How do conventional missiles fly?
My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?
Am I breaking OOP practice with this architecture?
What exactly is ineptocracy?
Does Dispel Magic work on Tiny Hut?
Mathematica command that allows it to read my intentions
Rotate ASCII Art by 45 Degrees
How can a day be of 24 hours?
What's the meaning of "Sollensaussagen"?
How to travel to Japan while expressing milk?
Unlock My Phone! February 2018
Getting extremely large arrows with tikzcd
Can I hook these wires up to find the connection to a dead outlet?
Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)
Placing the last line first in each html
- with sed
No, the challenge comes from me. I thought it was possible via the sed with knowledge I probably didn't have. But if this method exists, it suits me perfectly, as long as it does the job. I've never used "tak" and "awk" before, so you're teaching me something. So thanks for this !
– Elex XVII
yesterday
No, the challenge comes from me. I thought it was possible via the sed with knowledge I probably didn't have. But if this method exists, it suits me perfectly, as long as it does the job. I've never used "tak" and "awk" before, so you're teaching me something. So thanks for this !
– Elex XVII
yesterday
No, the challenge comes from me. I thought it was possible via the sed with knowledge I probably didn't have. But if this method exists, it suits me perfectly, as long as it does the job. I've never used "tak" and "awk" before, so you're teaching me something. So thanks for this !
– Elex XVII
yesterday
No, the challenge comes from me. I thought it was possible via the sed with knowledge I probably didn't have. But if this method exists, it suits me perfectly, as long as it does the job. I've never used "tak" and "awk" before, so you're teaching me something. So thanks for this !
– Elex XVII
yesterday
No, the challenge comes from me. I thought it was possible via the sed with knowledge I probably didn't have. But if this method exists, it suits me perfectly, as long as it does the job. I've never used "tak" and "awk" before, so you're teaching me something. So thanks for this !
– Elex XVII
yesterday
- Please be sure to answer the question. Provide details and share your research!
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use sed to print from the very first line until the line containing the last occurrence of a pattern?sed html parsingReplace only on the first matching line with sedHow to append the first line at the end of each line of a file with Sed?Deleting the second to last character in each line - with sedEdit HTML files from the command linedf -h command output in HTML format with specific columnsSed placing text after a certain linesed to insert a html values in a specific line numberUse sed to encapsulate the first word of each paragraph with <i> </i>?
I try to place the line "name: *****" just after the corresponding (innermost containing) "ul" each time an "ul" appears, so that it looks like this:
Before:
<ul>
<ul>
<li href="https://www.deepl.com/translator">DeepL</li>
<li href="https://translate.google.com">Google Trad</li>
name: "Translate",
</ul>
<li href="https://www.youtube.com/feed/subscriptions">Youtube</li>
<ul>
<li href="https://www.facebook.com/">Facebook</li>
<li href="https://twitter.com/">Twitter</li>
<li href="https://www.instagram.com">Instagram</li>
<li href="https://discordapp.com">Discord</li>
name: "Network",
</ul>
name: "Fav",
</ul>
After:
<ul>
name: "Fav",
<ul>
name: "Translate",
<li href="https://www.deepl.com/translator">DeepL</li>
<li href="https://translate.google.com">Google Trad</li>
</ul>
<li href="https://www.youtube.com/feed/subscriptions">Youtube</li>
<ul>
name: "Network",
<li href="https://www.facebook.com/">Facebook</li>
<li href="https://twitter.com/">Twitter</li>
<li href="https://www.instagram.com">Instagram</li>
<li href="https://discordapp.com">Discord</li>
</ul>
</ul>
So, I already tested a lot of things, like this:
sed -i -e 'N;s/<ul>([.n]*)n(.*),/2n1' fav.html
This and all I found to now doesn't work because the "name" following the last "ul" is not always the one to replace.
If anyone has an idea, I'd be happy to hear it.
text-processing sed text-formatting html
New contributor
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I try to place the line "name: *****" just after the corresponding (innermost containing) "ul" each time an "ul" appears, so that it looks like this:
Before:
<ul>
<ul>
<li href="https://www.deepl.com/translator">DeepL</li>
<li href="https://translate.google.com">Google Trad</li>
name: "Translate",
</ul>
<li href="https://www.youtube.com/feed/subscriptions">Youtube</li>
<ul>
<li href="https://www.facebook.com/">Facebook</li>
<li href="https://twitter.com/">Twitter</li>
<li href="https://www.instagram.com">Instagram</li>
<li href="https://discordapp.com">Discord</li>
name: "Network",
</ul>
name: "Fav",
</ul>
After:
<ul>
name: "Fav",
<ul>
name: "Translate",
<li href="https://www.deepl.com/translator">DeepL</li>
<li href="https://translate.google.com">Google Trad</li>
</ul>
<li href="https://www.youtube.com/feed/subscriptions">Youtube</li>
<ul>
name: "Network",
<li href="https://www.facebook.com/">Facebook</li>
<li href="https://twitter.com/">Twitter</li>
<li href="https://www.instagram.com">Instagram</li>
<li href="https://discordapp.com">Discord</li>
</ul>
</ul>
So, I already tested a lot of things, like this:
sed -i -e 'N;s/<ul>([.n]*)n(.*),/2n1' fav.html
This and all I found to now doesn't work because the "name" following the last "ul" is not always the one to replace.
If anyone has an idea, I'd be happy to hear it.
text-processing sed text-formatting html
New contributor
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
I try to place the line "name: *****" just after the corresponding (innermost containing) "ul" each time an "ul" appears, so that it looks like this:
Before:
<ul>
<ul>
<li href="https://www.deepl.com/translator">DeepL</li>
<li href="https://translate.google.com">Google Trad</li>
name: "Translate",
</ul>
<li href="https://www.youtube.com/feed/subscriptions">Youtube</li>
<ul>
<li href="https://www.facebook.com/">Facebook</li>
<li href="https://twitter.com/">Twitter</li>
<li href="https://www.instagram.com">Instagram</li>
<li href="https://discordapp.com">Discord</li>
name: "Network",
</ul>
name: "Fav",
</ul>
After:
<ul>
name: "Fav",
<ul>
name: "Translate",
<li href="https://www.deepl.com/translator">DeepL</li>
<li href="https://translate.google.com">Google Trad</li>
</ul>
<li href="https://www.youtube.com/feed/subscriptions">Youtube</li>
<ul>
name: "Network",
<li href="https://www.facebook.com/">Facebook</li>
<li href="https://twitter.com/">Twitter</li>
<li href="https://www.instagram.com">Instagram</li>
<li href="https://discordapp.com">Discord</li>
</ul>
</ul>
So, I already tested a lot of things, like this:
sed -i -e 'N;s/<ul>([.n]*)n(.*),/2n1' fav.html
This and all I found to now doesn't work because the "name" following the last "ul" is not always the one to replace.
If anyone has an idea, I'd be happy to hear it.
text-processing sed text-formatting html
New contributor
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I try to place the line "name: *****" just after the corresponding (innermost containing) "ul" each time an "ul" appears, so that it looks like this:
Before:
<ul>
<ul>
<li href="https://www.deepl.com/translator">DeepL</li>
<li href="https://translate.google.com">Google Trad</li>
name: "Translate",
</ul>
<li href="https://www.youtube.com/feed/subscriptions">Youtube</li>
<ul>
<li href="https://www.facebook.com/">Facebook</li>
<li href="https://twitter.com/">Twitter</li>
<li href="https://www.instagram.com">Instagram</li>
<li href="https://discordapp.com">Discord</li>
name: "Network",
</ul>
name: "Fav",
</ul>
After:
<ul>
name: "Fav",
<ul>
name: "Translate",
<li href="https://www.deepl.com/translator">DeepL</li>
<li href="https://translate.google.com">Google Trad</li>
</ul>
<li href="https://www.youtube.com/feed/subscriptions">Youtube</li>
<ul>
name: "Network",
<li href="https://www.facebook.com/">Facebook</li>
<li href="https://twitter.com/">Twitter</li>
<li href="https://www.instagram.com">Instagram</li>
<li href="https://discordapp.com">Discord</li>
</ul>
</ul>
So, I already tested a lot of things, like this:
sed -i -e 'N;s/<ul>([.n]*)n(.*),/2n1' fav.html
This and all I found to now doesn't work because the "name" following the last "ul" is not always the one to replace.
If anyone has an idea, I'd be happy to hear it.
text-processing sed text-formatting html
text-processing sed text-formatting html
New contributor
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 18 hours ago
G-Man
13.6k93770
13.6k93770
New contributor
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
Elex XVIIElex XVII
82
82
New contributor
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Elex XVII is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This may be impossible in sed.
(The challenge has been issued; I await being proved wrong.)
If you specifically require a sed solution,
you might as well stop reading this.
I was able to do it with a combination of tac and awk:
tac fav.html | awk '
/</ul>/ flag=1; level++;
/<ul>/ print save[level]; level--;
flag && /name/ flag=0; save[level] = $0; next;
print;
' | tac > fav.html.new && mv fav.html.new fav.html
tac fav.html reverses fav.html on a line-by-line basis
(tac is cat spelled backwards) and so produces
</ul>
name: "Fav",
</ul>
name: "Network",
<li href="https://discordapp.com">Discord</li>
︙
<ul>
︙
<ul>
<ul>
The first two lines of the awk code count the <ul> nesting level.
Since they are in reverse order, </ul> increases the level
and <ul> decreases it.
When we see a </ul>, we set flag to indicate that
we are entering a <ul> block from the bottom.
When we find a name near the bottom of a <ul> block, we save it,
and skip to the next line (without printing the name line).
When we find a <ul> (i.e., the beginning of a <ul> block),
we print the saved name before we print the <ul> itself.
The final tac reverses the lines again,
putting most of them back where they were originally,
and putting each name after its corresponding <ul>.
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
);
);
Elex XVII is a new contributor. Be nice, and check out our Code of Conduct.
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%2f509736%2fplacing-the-last-line-first-in-each-html-ul-with-sed%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
This may be impossible in sed.
(The challenge has been issued; I await being proved wrong.)
If you specifically require a sed solution,
you might as well stop reading this.
I was able to do it with a combination of tac and awk:
tac fav.html | awk '
/</ul>/ flag=1; level++;
/<ul>/ print save[level]; level--;
flag && /name/ flag=0; save[level] = $0; next;
print;
' | tac > fav.html.new && mv fav.html.new fav.html
tac fav.html reverses fav.html on a line-by-line basis
(tac is cat spelled backwards) and so produces
</ul>
name: "Fav",
</ul>
name: "Network",
<li href="https://discordapp.com">Discord</li>
︙
<ul>
︙
<ul>
<ul>
The first two lines of the awk code count the <ul> nesting level.
Since they are in reverse order, </ul> increases the level
and <ul> decreases it.
When we see a </ul>, we set flag to indicate that
we are entering a <ul> block from the bottom.
When we find a name near the bottom of a <ul> block, we save it,
and skip to the next line (without printing the name line).
When we find a <ul> (i.e., the beginning of a <ul> block),
we print the saved name before we print the <ul> itself.
The final tac reverses the lines again,
putting most of them back where they were originally,
and putting each name after its corresponding <ul>.
add a comment |
This may be impossible in sed.
(The challenge has been issued; I await being proved wrong.)
If you specifically require a sed solution,
you might as well stop reading this.
I was able to do it with a combination of tac and awk:
tac fav.html | awk '
/</ul>/ flag=1; level++;
/<ul>/ print save[level]; level--;
flag && /name/ flag=0; save[level] = $0; next;
print;
' | tac > fav.html.new && mv fav.html.new fav.html
tac fav.html reverses fav.html on a line-by-line basis
(tac is cat spelled backwards) and so produces
</ul>
name: "Fav",
</ul>
name: "Network",
<li href="https://discordapp.com">Discord</li>
︙
<ul>
︙
<ul>
<ul>
The first two lines of the awk code count the <ul> nesting level.
Since they are in reverse order, </ul> increases the level
and <ul> decreases it.
When we see a </ul>, we set flag to indicate that
we are entering a <ul> block from the bottom.
When we find a name near the bottom of a <ul> block, we save it,
and skip to the next line (without printing the name line).
When we find a <ul> (i.e., the beginning of a <ul> block),
we print the saved name before we print the <ul> itself.
The final tac reverses the lines again,
putting most of them back where they were originally,
and putting each name after its corresponding <ul>.
add a comment |
This may be impossible in sed.
(The challenge has been issued; I await being proved wrong.)
If you specifically require a sed solution,
you might as well stop reading this.
I was able to do it with a combination of tac and awk:
tac fav.html | awk '
/</ul>/ flag=1; level++;
/<ul>/ print save[level]; level--;
flag && /name/ flag=0; save[level] = $0; next;
print;
' | tac > fav.html.new && mv fav.html.new fav.html
tac fav.html reverses fav.html on a line-by-line basis
(tac is cat spelled backwards) and so produces
</ul>
name: "Fav",
</ul>
name: "Network",
<li href="https://discordapp.com">Discord</li>
︙
<ul>
︙
<ul>
<ul>
The first two lines of the awk code count the <ul> nesting level.
Since they are in reverse order, </ul> increases the level
and <ul> decreases it.
When we see a </ul>, we set flag to indicate that
we are entering a <ul> block from the bottom.
When we find a name near the bottom of a <ul> block, we save it,
and skip to the next line (without printing the name line).
When we find a <ul> (i.e., the beginning of a <ul> block),
we print the saved name before we print the <ul> itself.
The final tac reverses the lines again,
putting most of them back where they were originally,
and putting each name after its corresponding <ul>.
This may be impossible in sed.
(The challenge has been issued; I await being proved wrong.)
If you specifically require a sed solution,
you might as well stop reading this.
I was able to do it with a combination of tac and awk:
tac fav.html | awk '
/</ul>/ flag=1; level++;
/<ul>/ print save[level]; level--;
flag && /name/ flag=0; save[level] = $0; next;
print;
' | tac > fav.html.new && mv fav.html.new fav.html
tac fav.html reverses fav.html on a line-by-line basis
(tac is cat spelled backwards) and so produces
</ul>
name: "Fav",
</ul>
name: "Network",
<li href="https://discordapp.com">Discord</li>
︙
<ul>
︙
<ul>
<ul>
The first two lines of the awk code count the <ul> nesting level.
Since they are in reverse order, </ul> increases the level
and <ul> decreases it.
When we see a </ul>, we set flag to indicate that
we are entering a <ul> block from the bottom.
When we find a name near the bottom of a <ul> block, we save it,
and skip to the next line (without printing the name line).
When we find a <ul> (i.e., the beginning of a <ul> block),
we print the saved name before we print the <ul> itself.
The final tac reverses the lines again,
putting most of them back where they were originally,
and putting each name after its corresponding <ul>.
edited yesterday
answered 2 days ago
G-ManG-Man
13.6k93770
13.6k93770
add a comment |
No, the challenge comes from me. I thought it was possible via the sed with knowledge I probably didn't have. But if this method exists, it suits me perfectly, as long as it does the job. I've never used "tak" and "awk" before, so you're teaching me something. So thanks for this !
– Elex XVII
yesterday
No, the challenge comes from me. I thought it was possible via the sed with knowledge I probably didn't have. But if this method exists, it suits me perfectly, as long as it does the job. I've never used "tak" and "awk" before, so you're teaching me something. So thanks for this !
– Elex XVII
yesterday
add a comment |
Elex XVII is a new contributor. Be nice, and check out our Code of Conduct.
Elex XVII is a new contributor. Be nice, and check out our Code of Conduct.
Elex XVII is a new contributor. Be nice, and check out our Code of Conduct.
Elex XVII is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
But avoid …
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%2f509736%2fplacing-the-last-line-first-in-each-html-ul-with-sed%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