JREPL.BAT v8.6 - regex text processor with support for text highlighting and alternate character sets

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#61 Post by foxidrive » 07 Apr 2015 18:23

Your solution works again, Dave, thanks.

EDIT I've noticed that when I use /m I expected the entire text to be acted upon as one string.
The text has *** in several places and then .* is no longer greedy - it doesn't match until the last occurrence.


Code: Select all

@echo off

(
echo(aaa
echo(
echo(***
echo(
echo(bbb
echo(
echo(***
echo(
echo(
echo(***
echo(
echo(
echo(*** ***
echo(ZZZ
)>accounts.txt

:remove text at bottom from last *** and onward
echo ======
call jrepl "(.*)\*\*\*[\s\S]*" "" /m /f accounts.txt
echo ======
pause



This is what I see

======
aaa

======


Did I fail to grasp how /m works??

Original post follows:



Can you quickly comment on why .* doesn't match all characters and [\s\S]* does match all characters?
Is it something to do with line endings?

This top version similar to yours works but the lower one doesn't. I'm trying to understand why.

Code: Select all

call jrepl "^\*\*\*[\s\S]*" "" /m /f accounts.txt

call jrepl "^\*\*\*.*" "" /m /f accounts.txt

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

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#62 Post by dbenham » 07 Apr 2015 20:56

. matches any character except \n, which explains why .* stops matching at the end of a line.

\s matches any whitespace character (including \n)
\S matches any non-whitespace character

so [\s\S] matches any character

You could also use [\d\D]


Dave Benham

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#63 Post by foxidrive » 07 Apr 2015 23:56

dbenham wrote:. matches any character except \n, which explains why .* stops matching at the end of a line.


Ahh, the plot thickens. Ta!

You've probably mentioned that oodles of times before but my brain cell was overworked and I missed it.

\s matches any whitespace character (including \n)
\S matches any non-whitespace character

so [\s\S] matches any character

You could also use [\d\D]


Gotcha.

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#64 Post by Squashman » 23 Apr 2015 13:35

So we are making a change from Windows 2003 Server to Windows 2012 server. The software we are using is still coded for 32 bit so the path to the executable is going to change in all of my batch files.
So that is easy enough to change in all off my batch files.
Now I am going to use a FOR command to iterate through all of my batch files but for the sake of brevity we are strictly focusing on the JREPL syntax.

Code: Select all

jrepl "C:\Program Files\WatchDirectory" "C:\Program Files (x86)\WatchDirectory" /L /F ActiveDocIDQuiet.bat /O ActiveDocIDQuiet.bat.txt


The actual line it is changing is this.

Code: Select all

"C:\Program Files\WatchDirectory\wdrun.exe" -stop ActiveDocIDQuiet


What I really want to do is change it to this.

Code: Select all

start "" "C:\Program Files (x86)\WatchDirectory\wdrun.exe" -stop ActiveDocIDQuiet

There is no need for the batch file to wait for that command to finish before it executes the remaining commands in the batch file so I want to launch it with the start command instead.

How can I get the start and extra set of quotes before the program I am executing with one JREPL statement?

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

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#65 Post by dbenham » 23 Apr 2015 14:34

Code: Select all

jrepl "\qC:\Program Files\WatchDirectory" "start \q\q \qC:\Program Files (x86)\WatchDirectory" /L /X /F ActiveDocIDQuiet.bat /O ActiveDocIDQiet.bat.txt

You might want to consider making the search case insensitive, and you could also directly overwrite the source file as long as you have previously made a backup pre-changes.

Code: Select all

jrepl "\qC:\Program Files\WatchDirectory" "start \q\q \qC:\Program Files (x86)\WatchDirectory" /I /L /X /F ActiveDocIDQuiet.bat /O -


Dave Benham

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#66 Post by Squashman » 24 Apr 2015 09:08

Looks like I am going to have to do this in a two step process. Some of them had the start at the beginning already so I can't add another start.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#67 Post by foxidrive » 24 Apr 2015 21:27

If it has spaces before the actual term or is at the beginning of the line then the ^[ ]* should handle those cases and not change lines that already have start in them. Could it have leading tab characters too?



Code: Select all

call jrepl "^[ ]*\qC:\\Program Files\\WatchDirectory" "start \q\q \qC:\Program Files (x86)\WatchDirectory" /I /X /F "file.bat" /O -


I removed the /L literal switch and made a regular expression term - it works in my brief test here.

AtotIK
Posts: 1
Joined: 01 May 2015 13:54

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#68 Post by AtotIK » 01 May 2015 14:04

dbenham, hi! I use JREPL for package xml-files edit. But files more than 5kb will be cut when edit. Can you fix it? Or I do something wrong? Thanks!

Sample: http://www.mediafire.com/download/740g9wac13ihxzk/


@AtotIK; no double posting please.

Grahack
Posts: 3
Joined: 25 May 2015 00:19

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#69 Post by Grahack » 25 May 2015 00:42

Hi all,
I can't make jrepl work on several lines. Only the first is printed (see the test below). Is there a switch for jrepl to work on all the lines ?

Notes:
/A doesn't work either, even though all the lines are altered.
I don't want the behavior of /M )I'm using a regex like "^\q(.*)\q$".

Code: Select all

set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
echo first line%NL%second line | jrepl.bat i o

Grahack
Posts: 3
Joined: 25 May 2015 00:19

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#70 Post by Grahack » 03 Jun 2015 00:28

Hi all,
Is JREPL.BAT supposed to work on several lines?
See this test:

Code: Select all

set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
echo First line%NL%second line | jrepl.bat i o

It only prints «Forst lone».
Am I missing something?

chri

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#71 Post by foxidrive » 06 Jun 2015 01:18

There were three invisible posts above this one here - they just became visible.

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

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#72 Post by dbenham » 06 Jun 2015 06:50

Grahack wrote:Hi all,
Is JREPL.BAT supposed to work on several lines?
See this test:

Code: Select all

set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
echo First line%NL%second line | jrepl.bat i o

It only prints «Forst lone».
Am I missing something?

JREPL is working fine - The left side of the pipe is not producing what you think :!:

Each side of the pipe is executed in its own CMD /C process. You don't want %NL% to be expanded until it has reached the child process, so you simply delay the expansion by escaping each percent as %%.

Code: Select all

@echo off
setlocal
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
echo First line%%NL%%second line | jrepl.bat i o

Note - I'm not exactly sure how your original code produces the result that it does. It appears that the second line is simply dropped as if it never was there, but I don't understand the mechanism.

I suppose it has something to do with how batch parses a pipe - probably something that jeb has explained before that I am not remembering :?


Dave Benham

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

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#73 Post by dbenham » 06 Jun 2015 07:25

AtotIK wrote:dbenham, hi! I use JREPL for package xml-files edit. But files more than 5kb will be cut when edit. Can you fix it? Or I do something wrong? Thanks!

Sample: http://www.mediafire.com/download/740g9wac13ihxzk/


Sorry - your message got hung up in the system, and only now appeared.

There should not be any problem with a file bigger than 5kb - I have used JREPL with gigabyte files without a problem.

Note - If your file has NUL bytes (0x00), then you must use the /M option.

If /M does not solve your problem, then I have no idea how to help you. I do not understand what your posted link does, or how it relates to your problem. If you still need help, then please provide a better description of your problem, with example source file (uncompressed), and the exact JREPL command that is failing, with a description of the faulty output. If the file is really large or cannot be posted here for some other reason, then I prefer dropbox.


Dave Benham

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#74 Post by jeb » 06 Jun 2015 14:55

dbenham wrote:Note - I'm not exactly sure how your original code produces the result that it does. It appears that the second line is simply dropped as if it never was there, but I don't understand the mechanism.

I suppose it has something to do with how batch parses a pipe - probably something that jeb has explained before that I am not remembering :?


It's even better, you have posted yourself a solution which used this technic :D
How to split string without for loop in batch file

First I simplify the code

Code: Select all

set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
echo First line%NL%second line | more

After the first parser run in the batch file there is exactly one <LF> between "First line" and "second line".
This would produce two lines, but when this is transfer to the child cmd.exe (by the pipe) then the line is parsed again.
But then the linefeed is "raw" without the necessary esacping so it removes simply the rest of the line.
This results in the output of only "First line".

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

Re: JREPL.BAT - regex text processor - successor to REPL.BAT

#75 Post by dbenham » 06 Jun 2015 16:02

Thanks jeb - I remember now :roll: :oops:

Too many posts...


Dave Benham

Post Reply