Page 1 of 1

JREPL search and replace multiple occurrences

Posted: 18 Jan 2019 11:24
by Stevie
Hey all,

discovered JRELP yesterday and love it!

I have binary files, where I need to replace 3 strings. I want to do these replacements in one go and overwrite the original file.
Can anyone give me some tips how to achieve this?
That's what I got so far, but it's 3 different executions as you can see.

Code: Select all

JREPL.BAT "Nik4" "NiO5" /f InputFile /M /L /O InputFile
JREPL.BAT "5653544E696B346B6F6E74616B742034" "5653544E694F356B6F6E74616B742035" /f InputFile /M /L /O InputFile
JREPL.BAT "Kontakt 4" "Kontakt 5" /f InputFile /M /L /O InputFile

Re: JREPL search and replace multiple occurrences

Posted: 19 Jan 2019 08:40
by Stevie
Solved it by using "call".

Re: JREPL search and replace multiple occurrences

Posted: 19 Jan 2019 11:45
by dbenham
First off, you cannot specify the same output file as the input. If you want to overwrite the input file, then you must use a dash for the output name: /O -

If you want to specify multiple find/replace pairs, then you want the /T option. Use JREPL /?/T to get help on usage of the /T option.

Code: Select all

JREPL "Nik4|5653544E696B346B6F6E74616B742034|Kontakt 4" "NiO5|5653544E694F356B6F6E74616B742035|Kontakt 5" /M /L /T "|" /F "InputFile" /O -
Don't forget to use CALL JREPL if you put the command within a batch script. Without CALL, your batch script will terminate after the first JREPL execution. CALL enables your script to continue.


Dave Benham

Re: JREPL search and replace multiple occurrences

Posted: 19 Jan 2019 14:16
by Stevie
Ah thanks Dave!

Will check the T option. Since it's kind of a waste of resources to run thru the same file 3 times.
ANd yes, of course you are right, I used the /o - option to overwrite the same file.

Furthermore, I had to write a powershell script instead of a batch, because I'm running the script on an SMB drive and
I found out that DOS batches don't translate UNC paths.

Re: JREPL search and replace multiple occurrences

Posted: 19 Jan 2019 14:46
by Stevie
I just tried your code, but apparently powershell doesn't like the pipe in quotes.
I tried the escape character "\|", but that didn't help either. Any ideas how to solve this?

Re: JREPL search and replace multiple occurrences

Posted: 19 Jan 2019 17:08
by dbenham
You can use any character you want as the /T delimiter as long as it does not appear in any of your find or replace terms.

But I don't think you really have to use powershell.

I suggest you use PUSHD "\\serverName\pathToYourFile" to establish a temporary drive letter for your desired UNC path, and it also sets the current directory to the path at that drive letter. Then you need only supply the name of the file to JREPL. When you are done, simply POPD to return to your original location and drop the temporary UNC drive mapping.

Code: Select all

PUSHD "\\serverName\pathToYourFile"
CALL JREPL "Nik4|5653544E696B346B6F6E74616B742034|Kontakt 4" "NiO5|5653544E694F356B6F6E74616B742035|Kontakt 5" /M /L /T "|" /F "fileName" /O -
POPD

Dave Benham

Re: JREPL search and replace multiple occurrences

Posted: 19 Jan 2019 17:47
by Stevie
Amazing, that did the trick, switched to bat again and it works with pushd
Thanks a bunch Dave!

Powershell seems to have a general problem with the delimiter.

Re: JREPL search and replace multiple occurrences

Posted: 21 Jan 2019 15:31
by catalinnc
thanks a lot for the tips...
_