Post by marius-ciclistu » Tue Nov 21, 2017 7:01 pm

Hi.
As multiline search isn't available without a hack in OC 2.x and 3.x please tell me how to replace only the first occcurrence of a line "code;" with ocmod.

example

Code: Select all

	<file path="catalog/...">
		<operation  error="abort">
			<search><![CDATA[
		code;
			]]></search>
			<add position="replace"><![CDATA[
                new code;
			]]></add>
		</operation>
Thank you

New member

Posts

Joined
Sat Nov 24, 2012 6:22 am

Post by kestas » Tue Nov 21, 2017 7:41 pm

marius-ciclistu wrote:
Tue Nov 21, 2017 7:01 pm
Hi.
As multiline search isn't available without a hack in OC 2.x and 3.x please tell me how to replace only the first occcurrence of a line "code;" with ocmod.

example

Code: Select all

	<file path="catalog/...">
		<operation  error="abort">
			<search><![CDATA[
		code;
			]]></search>
			<add position="replace"><![CDATA[
                new code;
			]]></add>
		</operation>
Thank you
Hi,

try to add

Code: Select all

index="1"
...

Code: Select all

<search index="1">
Cheers

Custom OpenCart modules and solutions. Just PM me... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by marius-ciclistu » Tue Nov 21, 2017 7:47 pm

I foud this: https://github.com/vqmod/vqmod/wiki/Scripting
modification / file / operation / search

Optional attribute "index" for specifying which instances of a search tag should be acted on

If the search string is "echo" and there are 5 echos in the file, but only want to replace the 1st and 3rd, use index="1,3"

So I gues <search index="1"> is the answer.
EDIT
Thank you kestas for the answer. I saw it after I posted this reply:)

New member

Posts

Joined
Sat Nov 24, 2012 6:22 am

Post by marius-ciclistu » Tue Nov 21, 2017 8:05 pm

kestas wrote:
Tue Nov 21, 2017 7:41 pm
marius-ciclistu wrote:
Tue Nov 21, 2017 7:01 pm
Hi.
As multiline search isn't available without a hack in OC 2.x and 3.x please tell me how to replace only the first occcurrence of a line "code;" with ocmod.

example

Code: Select all

	<file path="catalog/...">
		<operation  error="abort">
			<search><![CDATA[
		code;
			]]></search>
			<add position="replace"><![CDATA[
                new code;
			]]></add>
		</operation>
Thank you
Hi,

try to add

Code: Select all

index="1"
...

Code: Select all

<search index="1">
Cheers
I tried and in the logs the line shown is 665 in a file that has 662 lines and the occurrences at 159 and 624.... something is not ok.
Opencart 2.3.x


index="0" is the right answer.

New member

Posts

Joined
Sat Nov 24, 2012 6:22 am

Post by kestas » Tue Nov 21, 2017 8:24 pm

index="0" is the right answer.
oh yes sorry, it is maybe my mistake, but anyway the right direction can get us to the right place.. ;)

Cheers
Last edited by kestas on Wed Nov 22, 2017 1:53 pm, edited 1 time in total.

Custom OpenCart modules and solutions. Just PM me... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by IP_CAM » Wed Nov 22, 2017 11:07 am

index="0" is the right answer.
well, this is new to me, so far, I always used index="1", to make something work
on the first corresponding anchor-line ONLY. Just to mention this ! ;)
Ernie

Code: Select all

Optional attribute "index" for specifying which instances of a search tag should be acted on
If the search string is "echo" and there are 5 echos in the file, but only want to replace the 1st and 3rd, use index="1,3"
https://github.com/vqmod/vqmod/wiki/Scripting

Ernie's OpenCart v.1.5.6.5 LIGHT + OpenShop Admin v.1.75 Test Sites
http://www.ebikes.li - http://www.evelo.li - http://www.openshop.li
Image


User avatar
Guru Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by marius-ciclistu » Wed Nov 22, 2017 4:24 pm

I saw that explanation but for me, with index='1' it replaced the second occurance in a file in oc 2.3.x .

New member

Posts

Joined
Sat Nov 24, 2012 6:22 am

Post by marius-ciclistu » Wed Nov 22, 2017 5:07 pm

IP_CAM wrote:
Wed Nov 22, 2017 11:07 am
index="0" is the right answer.
well, this is new to me, so far, I always used index="1", to make something work
on the first corresponding anchor-line ONLY. Just to mention this ! ;)
Ernie

Code: Select all

Optional attribute "index" for specifying which instances of a search tag should be acted on
If the search string is "echo" and there are 5 echos in the file, but only want to replace the 1st and 3rd, use index="1,3"
https://github.com/vqmod/vqmod/wiki/Scripting

You can test if you want with the 3.x version here ( the 2.3.x version doesn't need index in this mod):
https://www.opencart.com/index.php?rout ... load_id=55

(I made another mod with oc 2.3.x and index="0" but that is not public)

New member

Posts

Joined
Sat Nov 24, 2012 6:22 am
Who is online

Users browsing this forum: No registered users and 12 guests