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

Message
Author
Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#271 Post by Squashman » 01 Mar 2017 13:20

catalinnc wrote:@dbenham

i have this text file:

Code: Select all

somerandomblablablaSTARTmorerandomblablablaENDlastrandomblablabla


can i use this tool (in a .bat) to insert a new line (hex sequence 0x0d0a) before START and after END in one ore more steps?
_

So you want the output to look like this?

Code: Select all

somerandomblablabla
STARTmorerandomblablablaEND
lastrandomblablabla

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

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

#272 Post by catalinnc » 01 Mar 2017 13:26

indeed...
_

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

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

#273 Post by Squashman » 01 Mar 2017 13:40

Code: Select all

jrepl "START.*END" "\r\n$&\r\n" /X /f file.txt /O -

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

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

#274 Post by Aacini » 01 Mar 2017 14:06

Code: Select all

@set @a=0 /* & echo off

echo somerandomblablablaSTARTmorerandomblablablaENDlastrandomblablabla > file.txt
cscript //nologo //E:JScript "%~F0" < file.txt > file.tmp
move /Y file.tmp file.txt > NUL

goto :EOF */


WScript.Stdout.Write(WScript.Stdin.ReadAll().replace(/START.*END/g,"\r\n$&\r\n"));

Antonio

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

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

#275 Post by catalinnc » 02 Mar 2017 13:04

@Squashman and @Aacini

thanks a lot for your help...
_

Dylan666
Posts: 1
Joined: 09 Mar 2017 11:14

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

#276 Post by Dylan666 » 09 Mar 2017 11:22

Hi, please help me to solve this problem :D
I have this text file caller MyLog.txt :

Code: Select all

Line one bla bla bla
Line two OK bla bla bla

Line one bla bla bla
Line two ERROR bla bla bla
Line three bla bla bla

Line one bla bla bla
Line two OK bla bla bla

Line one bla bla bla
Line two OK bla bla bla

Line one bla bla bla
Line two ERROR bla bla bla
Line three bla bla bla

Line one bla bla bla
Line two OK bla bla bla


I need to keep all the groups of 3 lines with "error" and delete the groups of two lines containing "ok"
Maybe I need to split the text in paragraph using the blank lines as separator.

Any suggestion?

Thanks in advance

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

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

#277 Post by Squashman » 09 Mar 2017 12:40

Dylan666 wrote:I need to keep all the groups of 3 lines with "error" and delete the groups of two lines containing "ok"
Maybe I need to split the text in paragraph using the blank lines as separator.

Any suggestion?

Thanks in advance

I am not understanding your requirements. Can you please show us what your expected output should be.

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

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

#278 Post by Aacini » 09 Mar 2017 13:50

Like this one, perhaps?

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set "i=0"
set "error="
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" MyLog.txt') do (
   if "%%b" equ "" (
      if defined error (for /L %%i in (1,1,!i!) do echo !line[%%i]!) & echo/
      set "i=0"
      set "error="
   ) else (
      set /A i+=1
      for /F %%i in ("!i!") do (
         set "line[%%i]=%%b"
         if !i! equ 2 if "!line[%%i]:ERROR=!" neq "%%b" set "error=1"
      )
   )
)
if defined error for /L %%i in (1,1,!i!) do echo !line[%%i]!

Output:

Code: Select all

Line one bla bla bla
Line two ERROR bla bla bla
Line three bla bla bla

Line one bla bla bla
Line two ERROR bla bla bla
Line three bla bla bla

Antonio

Mike D
Posts: 6
Joined: 18 Aug 2016 19:38
Location: Canberra, Australia

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

#279 Post by Mike D » 09 Mar 2017 14:52

Code: Select all

jrepl "ERROR" "" /K 1:2 /F MyLog.txt

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

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

#280 Post by Squashman » 09 Mar 2017 16:26

Mike D wrote:

Code: Select all

jrepl "ERROR" "" /K 1:2 /F MyLog.txt

That's nice. Didn't know you could do that with JREPL.

You are officially Foxidrive's replacement. Err....well we really can't replace his charm......but another Aussie will do.
:D

zimxavier
Posts: 53
Joined: 17 Jan 2016 10:09
Location: France

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

#281 Post by zimxavier » 09 Apr 2017 08:38

Hi! :)
I use JREPL 6.6

1.
I need to extract all lines from the first to the 1500th. I use \inc option but it doesn't work. (ERROR: invalid option)

Code: Select all

call JREPL ".*" "$0" /jmatch /INC: "1:1500" /f file.txt /o -

I tested for replacing and same result:

Code: Select all

call JREPL ".*" "" /i /INC: "1:1500" /x /f file.txt /o -

2.
I use this code for updating some lines:

Code: Select all

@echo off
for /f "delims=" %%a in ('dir /b /a-d "DATA\*.txt" ') do (
call JREPL "VARIABLE_ALL_CULTURES: .*$" "stdin.AtEndOfStream?$0:stdin.ReadLine()" /j /f "DATA\%%~a" <"TEMP\all_cultures.txt" /o -
)

I would like to test the new version with jq. What should be the new code ?

Thanks for any help

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

#282 Post by dbenham » 09 Apr 2017 10:29

zimxavier wrote:I need to extract all lines from the first to the 1500th. I use \inc option but it doesn't work. (ERROR: invalid option)

Code: Select all

call JREPL ".*" "$0" /jmatch /INC: "1:1500" /f file.txt /o -
Oops :oops: - There is a documentation error in the examples. The /INC and /EXC options should not have a trailing colon. I will release v6.7 to fix the docs.

Your regex is wrong because it will match and preserve the entire line, and then .* will also match the end of line, resulting in a blank line after every matched line. That can be fixed by using "^.*" to match only from the beginning of the line.
Also, the /JMATCHQ option is faster than /JMATCH

Code: Select all

call JREPL "^.*" "$txt=$0" /jmatchq /inc "1:1500" /f file.txt /o -

There is a simpler solution using the /K option to keep lines that have at least one regex match. The 0 after /K means do not include any additional lines before or after a match.

Code: Select all

call JREPL "^" "" /k 0 /inc "1:1500" /f file.txt /o -


zimxavier wrote:I use this code for updating some lines:

Code: Select all

@echo off
for /f "delims=" %%a in ('dir /b /a-d "DATA\*.txt" ') do (
call JREPL "VARIABLE_ALL_CULTURES: .*$" "stdin.AtEndOfStream?$0:stdin.ReadLine()" /j /f "DATA\%%~a" <"TEMP\all_cultures.txt" /o -
)

I would like to test the new version with jq. What should be the new code ?
Couldn't be much simpler ;-)

Code: Select all

call JREPL "VARIABLE_ALL_CULTURES: .*$" "$txt=stdin.AtEndOfStream?$0:stdin.ReadLine()" /jq /f "DATA\%%~a" <"TEMP\all_cultures.txt" /o -


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

#283 Post by dbenham » 09 Apr 2017 10:53

Here is version 6.7
JREPL6.7.zip
1340 downloads from the main release page when v6.7 was the current release (4+ months)
(19.01 KiB) Downloaded 738 times

The only changes are fixes to documentation:
- Corrected /OFF documentation to include /JMATCHQ and /MATCH
- Fixed /INC and /EXC examples - eliminated unwanted colon after option
- Corrected various spelling errors pointed out to me by brinda in a private message


Dave Benham

zimxavier
Posts: 53
Joined: 17 Jan 2016 10:09
Location: France

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

#284 Post by zimxavier » 10 Apr 2017 06:04

It works great, as usual. Thank you :)

takedown
Posts: 1
Joined: 12 Apr 2017 07:28

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

#285 Post by takedown » 12 Apr 2017 07:45

Hi there,
I'm first time using "REPL.BAT" tool and still can't quite figure it out how to work with the syntax.
The issue is that i have a text file with a long string in one line :

Code: Select all

<pre> 3/16/2017 11:20 AM        &lt;dir&gt; <A HREF="/App_Data/">App_Data</A><br> 3/20/2017  8:00 AM          256 <A HREF="/Avg-2013.zip.sig">Avg-2013.zip.sig</A><br> 3/12/2017  8:01 AM    124068275 <A HREF="/Avg-2014.zip">Avg-2014.zip</A><br>

How can i syntax "REPL.BAT" to make a new line (split) after each time the word <br> is shown

e.g.

Code: Select all

3/16/2017 11:20 AM        &lt;dir&gt; <A HREF="/App_Data/">App_Data</A><br> 
3/20/2017  8:00 AM          256 <A HREF="/Avg-2013.zip.sig">Avg-2013.zip.sig</A><br>
3/12/2017  8:01 AM    124068275 <A HREF="/Avg-2014.zip">Avg-2014.zip</A><br>

Thanks in advanced for the help

Post Reply