Page 10 of 10

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

Posted: 26 Oct 2018 06:26
by et_phonehome_2
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?

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

Posted: 27 Oct 2018 09:29
by Aacini
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

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

Posted: 24 Jan 2019 09:04
by et_phonehome_2
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%

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

Posted: 24 Jan 2019 09:19
by et_phonehome_2
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

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

Posted: 26 Aug 2019 18:29
by SIMMS7400
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.