Page 1 of 1

sandr first occurrence

Posted: Mon Oct 30, 2023 11:43 am
by josmani
Hi Guys,

I need some help to sandr the first occurrence of a text in data file.

<$data= "adfafd adsf <tag> text test <tag> <tag>bla bla <component> test text </tag></tag>">

I like to change the first <tag> to <tag2>, how can I achieve this?

Best

Re: sandr first occurrence

Posted: Mon Oct 30, 2023 11:58 am
by John
In your example your tags aren't balanced. Is it just the first open <tag> you are trying to replace, or also change a closing </tag> with possible other <tag></tag> inside?

Re: sandr first occurrence

Posted: Mon Oct 30, 2023 12:02 pm
by josmani
I have multiple occurrences of <tag>..</tag> in data but want to only rename the the first occurrence of opening and closing to something else. They are not inside each other.

Re: sandr first occurrence

Posted: Mon Oct 30, 2023 12:11 pm
by John
You should be able to use:

<sandr ">>=!<tag>*<tag>=!</tag>+</tag>=" "\2<tag2>\4</tag2>" $data>

The >>= will anchor to the beginning.