Page 19 of 37

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

Posted: 01 Mar 2017 13:20
by Squashman
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

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

Posted: 01 Mar 2017 13:26
by catalinnc
indeed...
_

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

Posted: 01 Mar 2017 13:40
by Squashman

Code: Select all

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

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

Posted: 01 Mar 2017 14:06
by Aacini

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

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

Posted: 02 Mar 2017 13:04
by catalinnc
@Squashman and @Aacini

thanks a lot for your help...
_

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

Posted: 09 Mar 2017 11:22
by Dylan666
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

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

Posted: 09 Mar 2017 12:40
by Squashman
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.

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

Posted: 09 Mar 2017 13:50
by Aacini
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

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

Posted: 09 Mar 2017 14:52
by Mike D

Code: Select all

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

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

Posted: 09 Mar 2017 16:26
by Squashman
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

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

Posted: 09 Apr 2017 08:38
by zimxavier
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

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

Posted: 09 Apr 2017 10:29
by dbenham
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

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

Posted: 09 Apr 2017 10:53
by dbenham
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 769 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

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

Posted: 10 Apr 2017 06:04
by zimxavier
It works great, as usual. Thank you :)

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

Posted: 12 Apr 2017 07:45
by takedown
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