JREPL search and replace multiple occurrences

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Stevie
Posts: 5
Joined: 18 Jan 2019 11:19

JREPL search and replace multiple occurrences

#1 Post by Stevie » 18 Jan 2019 11:24

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

Stevie
Posts: 5
Joined: 18 Jan 2019 11:19

Re: JREPL search and replace multiple occurrences

#2 Post by Stevie » 19 Jan 2019 08:40

Solved it by using "call".

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: JREPL search and replace multiple occurrences

#3 Post by dbenham » 19 Jan 2019 11:45

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

Stevie
Posts: 5
Joined: 18 Jan 2019 11:19

Re: JREPL search and replace multiple occurrences

#4 Post by Stevie » 19 Jan 2019 14:16

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.

Stevie
Posts: 5
Joined: 18 Jan 2019 11:19

Re: JREPL search and replace multiple occurrences

#5 Post by Stevie » 19 Jan 2019 14:46

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?

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: JREPL search and replace multiple occurrences

#6 Post by dbenham » 19 Jan 2019 17:08

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

Stevie
Posts: 5
Joined: 18 Jan 2019 11:19

Re: JREPL search and replace multiple occurrences

#7 Post by Stevie » 19 Jan 2019 17:47

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.

catalinnc
Posts: 39
Joined: 12 Jan 2015 11:56

Re: JREPL search and replace multiple occurrences

#8 Post by catalinnc » 21 Jan 2019 15:31

thanks a lot for the tips...
_

Post Reply