FindRepl.bat:New regex utility to search and replace strings

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
et_phonehome_2
Posts: 3
Joined: 26 Oct 2018 05:55

Re: FindRepl.bat:New regex utility to search and replace strings

#136 Post by et_phonehome_2 » 26 Oct 2018 06:26

I am trying to use this inside a DOS batch script to dynamically generate scripts based upon incoming parameters.
I have the following as an example:

Of course the set variable values is actually passed into this script and not hard-coded as shown:

set PARM="filename with space"
set FNAME="d:\directory\subdir with space"
set COMMENT="comment with spaces"
< TEST.txt FindRepl "replPARM|replFNAME|replCOMMENT" /A "=%PARM%|%FNAME%|%COMMENT%" > TEST_NEW.txt

I am unable to get the variable substitution, is there a way to get this working or must I do this differently?

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: FindRepl.bat:New regex utility to search and replace strings

#137 Post by Aacini » 27 Oct 2018 09:29

Ok. A couple points about your concern.

First of all, these commands:

Code: Select all

set PARM="filename with space"
set FNAME="d:\directory\subdir with space"
set COMMENT="comment with spaces"
assigns to the variables the values placed after the equal sign including the quotes. These quotes interfere with posterior commands when the variables are expanded. The right way is this:

Code: Select all

set "PARM=filename with space"
set "FNAME=d:\directory\subdir with space"
set "COMMENT=comment with spaces"
In this command:

Code: Select all

< TEST.txt FindRepl "replPARM|replFNAME|replCOMMENT" /A "=%PARM%|%FNAME%|%COMMENT%" > TEST_NEW.txt
The equal-sign is not required. The equal-sign is used in a different way as described at the first post in this thread, under the 4. Storing search strings in Batch variables header.

Antonio

et_phonehome_2
Posts: 3
Joined: 26 Oct 2018 05:55

Re: FindRepl.bat:New regex utility to search and replace strings

#138 Post by et_phonehome_2 » 24 Jan 2019 09:04

I want to exclude the BEGIN and END lines on one pass.

eg., Input data looks like this:
….
[NAME001]
somevalue001
[END]
[NAME002]
somevalue002A
somevalue002B
somevalue002C
[END]
……..

where PARTNER=NAME002
COMPUTERNAME=somevalue00B

I want to exclude the BEGIN and END lines [NAME002] and [END]. Is there a way to exclude it without performing a pipe to findrepl again to exclude the two lines?

type %PARTNER_CONFIG% | findrepl "^\[%PARTNER%\]" /E:"\[END\]" | findrepl /I /V "%COMPUTERNAME%

et_phonehome_2
Posts: 3
Joined: 26 Oct 2018 05:55

Re: FindRepl.bat:New regex utility to search and replace strings

#139 Post by et_phonehome_2 » 24 Jan 2019 09:19

Bug detected when I run my command more than once:
First time it works, 2nd and succeeding run fails; it will take awhile before it will work again.

>type %PARTNER_CONFIG% | findrepl "^\[%PARTNER%\]" /E:"\[END\]" | findrepl /I /V "%COMPUTERNAME%"
The system cannot find the file specified.
D:\MyApps\scripts\FindRepl.bat(318, 1) Microsoft JScript runtime error: Permission denied
D:\MyApps\scripts\FindRepl.bat(784, 4) Microsoft JScript runtime error: Input past end of file

>type %PARTNER_CONFIG% | findrepl "^\[%PARTNER%\]" /E:"\[END\]" | findrepl /I /V "%COMPUTERNAME%"
The system cannot find the file specified.
D:\MyApps\scripts\FindRepl.bat(322, 1) Microsoft JScript runtime error: Input past end of file
D:\MyApps\scripts\FindRepl.bat(325, 1) Microsoft JScript runtime error: Permission denied


>type %PARTNER_CONFIG% | findrepl "^\[%PARTNER%\]" /E:"\[END\]" | findrepl /I /V "%COMPUTERNAME%"
The system cannot find the file specified.
D:\MyApps\scripts\FindRepl.bat(784, 4) Microsoft JScript runtime error: Input past end of file
D:\MyApps\scripts\FindRepl.bat(784, 4) Microsoft JScript runtime error: Input past end of file

>type %PARTNER_CONFIG% | findrepl "^\[%PARTNER%\]" /E:"\[END\]" | findrepl /I /V "%COMPUTERNAME%"
The system cannot find the file specified.
D:\MyApps\scripts\FindRepl.bat(784, 4) Microsoft JScript runtime error: Input past end of file
D:\MyApps\scripts\FindRepl.bat(784, 4) Microsoft JScript runtime error: Input past end of file

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: FindRepl.bat:New regex utility to search and replace strings

#140 Post by SIMMS7400 » 26 Aug 2019 18:29

HI There -

I'm trying to use this script and it works fine on my local machine. But when I promote to my server, I'm getting permission denied on line 318 of FINDREPL. ANy ideas why? I have write access to the directory.

Post Reply