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?
FindRepl.bat:New regex utility to search and replace strings
Moderator: DosItHelp
-
- Posts: 3
- Joined: 26 Oct 2018 05:55
Re: FindRepl.bat:New regex utility to search and replace strings
Ok. A couple points about your concern.
First of all, these commands:
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:
In this command:
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
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"
Code: Select all
set "PARM=filename with space"
set "FNAME=d:\directory\subdir with space"
set "COMMENT=comment with spaces"
Code: Select all
< TEST.txt FindRepl "replPARM|replFNAME|replCOMMENT" /A "=%PARM%|%FNAME%|%COMMENT%" > TEST_NEW.txt
Antonio
-
- Posts: 3
- Joined: 26 Oct 2018 05:55
Re: FindRepl.bat:New regex utility to search and replace strings
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%
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%
-
- Posts: 3
- Joined: 26 Oct 2018 05:55
Re: FindRepl.bat:New regex utility to search and replace strings
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
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
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.
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.