ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I kinda suck with sed. I need sed (gnu or other) expression to remove lines inclusive of a from pattern to an end pattern. "marker1" and "marker2" are the text patterns. from:
Code:
<tag1>
<!-- marker1 -->
d
d
d
<!-- marker2 -->
</tag1>
There are a lot of ways to do this in sed; putting "sed remove from between patterns" into any search-engine will give you lots. You say you're stuck, but don't show us what you're stuck ON, or show your efforts. This also seems like some sort of JSON/XML/HTML code, and there are FAR better tools to parse up HTML/JSON/structured data.
There are a lot of ways to do this in sed; putting "sed remove from between patterns" into any search-engine will give you lots. You say you're stuck, but don't show us what you're stuck ON, or show your efforts. This also seems like some sort of JSON/XML/HTML code, and there are FAR better tools to parse up HTML/JSON/structured data.
Between patterns I had working after modifications.
But then my other code didn't work ok with that.
So now I needed to do pattern to pattern inclusive delete.
Like I said, my sed skills are crappy, and I am testing sed between ubuntu and android, and the android sed comes from in toybox, I have to escape the "!" otherwise sed fails.
But I don't really need to pattern match the whole marker tag, just need to pattern the words "marker1" and "marker2", which means no more "!" issue.
A greatful thanks for the replies.
Last edited by Linux_Kidd; 03-12-2024 at 09:04 PM.
it is answered, I think. I can add only a remark: you can use . (dot) instead of those strange characters (like |), sometimes that helps.
We have no info about your other code, therefore can't help on that.
ptndel () {
local File="$1"
local SedCmd='s;[].*[\\/];\\&;g'
local From=$(sed "$SedCmd" <<<"$2")
local To=$(sed "$SedCmd" <<<"$3")
sed "/$From/,/$To/d" "$File"
}
ptndel () {
local File="$1"
local SedCmd='s;[\[\]\.\\\/];\\&;g'
local From=$(sed "$SedCmd" <<<"$2")
local To=$(sed "$SedCmd" <<<"$3")
sed "/$From/,/$To/d "$File"
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.