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
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#181 Post by foxidrive » 09 May 2016 18:36

The /T switch should help to solve that.

Aside to Dave: The /T switch has no documentation to show the syntax in the jrepl help.

Newbies like me can't figure out how to use it for multiple characters.

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

#182 Post by dbenham » 09 May 2016 22:29

No need for the /T switch on this simple request. Just a normal regex character set is all you need, plus you need to worry about how many times to double up the percent within a batch file, plus an escape sequence for the quote.

From the command line:

Code: Select all

jrepl "[=%\q^!<>&|]" " " /x /f input.txt /o output.txt

From within a batch script:

Code: Select all

call jrepl "[=%%%%\q^!<>&|]" " " /x /f input.txt /o output.txt


Dave Benham

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

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

#183 Post by catalinnc » 10 May 2016 12:39

@dbenham thanks a lot for your support...much respect...
_

Code: Select all

jrepl "[=%\q^!<>&|]" " " /x /f input.txt /o output.txt


works perfect from command-line prompt...
_

Code: Select all

call jrepl "[=%%%%\q^!<>&|]" " " /x /f input.txt /o output.txt


works perfect from a .bat file!
_

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

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

#184 Post by zimxavier » 04 Jun 2016 16:45

Hello :-)

I have 2 issues with JREPL.BAT

1) FIRST ISSUE

In my batch:
call jrepl.bat "\[[A-Za-z0-9_.]*?FatherMother\]" "mère" /x /f TEMP\all_lines.txt /o -
call jrepl.bat "\[[A-Za-z0-9_.]*?MasterMistress\]" "maîtresse" /x /f TEMP\all_lines.txt /o -


In my file I have now mÞre and ma¯tresse.

REPL.BAT is incompatible with accents or I missed something ?

2)SECOND ISSUE

In my batch:
call jrepl.bat "§Y" "" /x /f TEMP\all_lines.txt /o -

I want to remove all §Y in my file, but there is no change in my file.
Last edited by zimxavier on 08 Jun 2016 08:47, edited 1 time in total.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

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

#185 Post by penpen » 04 Jun 2016 18:15

REPL.BAT is incompatible with accents or I missed something ?
I am not familiar with JREPL (so i cannot help you with "Point 3)"), but it is a JScript application, so i doubt that it is incompatible with accents:
If i remember right it internally uses UTF16, so no character should be a problem.

I think your issues are all codepage related.

I bet your editor (on which you have created the batch file) is using the codepage 1252, and
the cmd window where you have executed the batch is using codepage 850:
You type the character U+00E8 (è) into your editor (notepad?).
When you save it to disk you probably use ANSI file format, so this character is translated to the byte 0xE8.
The cmd shell interprets this byte as the character U+00FE (Þ).

The same happens to the other characters:
U+00EE (î) --> 0xEE --> U+00AF (¯).
U+00A7 (§) --> 0xA7 --> U+00BA (º).


Depending on what characters you are using, it may help you to change the codepage of your command window to 1252:

Code: Select all

chcp 1252


penpen

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

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

#186 Post by zimxavier » 05 Jun 2016 02:19

It works, thank you penpen :-)

john67z
Posts: 1
Joined: 17 Jun 2016 09:48

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

#187 Post by john67z » 17 Jun 2016 10:19

I have fixed width file with pipe delimeters that sometimes will have a carriage return line feed in one of the columns when it shouldn't. For example:

Code: Select all

Line 1:  PC16ABCDEF01|this|is|normal....|****|<CRLF>
Line 2:  PC16ACCDEF02|this|is|not<CRLF>
Line 2:  normal.|****|<CRLF>



As you can see, line 2 has a carriage return line feed before the normal end of the line. A normal line in this example is 37 characters long.
I need to replace any CRLF with a space when the CRLF does not start in position 38. Is this possible with JREPL? The reason I need to do this is because I am loading the text file into a SQL database using BULK INSERT. It fails when it encounters one of the malformed lines. I am working with the people who create the text file to fix this before they send it to me. However, in case they can't and to have a backup, I am trying to figure out an alternative.

Thanks

bluesky088
Posts: 4
Joined: 18 Jun 2016 21:21

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

#188 Post by bluesky088 » 18 Jun 2016 21:27

Hi,

I'm new to this forum and the use of Jreply.bat.

Would like some advise on the use of Jeply.bat to replace a particular line (in this case line 4) in one of my configuration files. Sample code from configuration file is as follows:

Code: Select all

[global]
; Comments 1
; Comments 2
From=aaa<bbb@ccc.com>

; Comment 3
; Comment 4"
DefaultGroup="aaa.bbb.ccc"


I saw someone mention the use of the following Jrepl command for this purpose. But nothing seems to happen when I execute the command. Any assistance is greatly appreciated.

Code: Select all

jrepl "^From.*" "NewLine4Here" /jbegln "skip=(ln!=5)" /f "C:\Users\David\Desktop\Test\.gopoststuff1.conf" /o -

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

#189 Post by dbenham » 18 Jun 2016 22:14

john67z wrote:I have fixed width file with pipe delimeters that sometimes will have a carriage return line feed in one of the columns when it shouldn't. For example:

Code: Select all

Line 1:  PC16ABCDEF01|this|is|normal....|****|<CRLF>
Line 2:  PC16ACCDEF02|this|is|not<CRLF>
Line 2:  normal.|****|<CRLF>

As you can see, line 2 has a carriage return line feed before the normal end of the line. A normal line in this example is 37 characters long.
I need to replace any CRLF with a space when the CRLF does not start in position 38. Is this possible with JREPL? The reason I need to do this is because I am loading the text file into a SQL database using BULK INSERT. It fails when it encounters one of the malformed lines. I am working with the people who create the text file to fix this before they send it to me. However, in case they can't and to have a backup, I am trying to figure out an alternative.

Perhaps not intuitive, but the following simple command should do the trick:

Code: Select all

jrepl "([\r\n]*[^\r\n]){37}" "$0.replace(/\r|\n/g,'')" /jmatch /m /f input.txt /o -

It uses the /M option to allow searches across multiple lines, and the /JMATCH option to only print out the replacement strings for each match (with <CR><LF> appended to each).

The search matches characters until it finds exactly 37 characters that are not <CR> or <LF>. The replacement string is the entire matched string, which then uses the JScript replace() function to replace all <CR> and <LF> with an empty string.

The /O - option overwrites the original file with the end result. Replace the - with a different file name if you want to preserve the original file.


Dave Benham
Last edited by dbenham on 19 Jun 2016 07:50, edited 2 times in total.

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

#190 Post by dbenham » 18 Jun 2016 22:30

JREPL has had the ability to process specific lines of a file since version 3.0 (released 2014-11-23), but that required user supplied JScript code involving the skip and ln variables via the /JBEGLN option.

It seems that specifying line numbers is a common need, but most users seem to be uncomfortable with providing user supplied JScript.

So I decided to add the /INC and /EXC options to specify which lines to include/exclude. This is much easier to use :)

For example, to remove lines 10 through 15 with the new version 4.0:

Code: Select all

jrepl "^.*" $0 /jmatch /exc "10:15" /f test.txt /o -

To accomplish the same thing with version 3.8 (this also works in 4.0, but is less convenient):

Code: Select all

jrepl "^.*" $0 /jmatch /jbegln "skip=(ln>=10&&ln<=15)" /f test.txt /o -


As always, full documentation is embedded within the file, including some more complicated examples showing how the new options work.

JREPL.BAT version 4.0
JREPL4.0.zip
(9.84 KiB) Downloaded 920 times


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

#191 Post by dbenham » 19 Jun 2016 07:58

bluesky088 wrote:Would like some advise on the use of Jeply.bat to replace a particular line (in this case line 4) in one of my configuration files. Sample code from configuration file is as follows:

Code: Select all

[global]
; Comments 1
; Comments 2
From=aaa<bbb@ccc.com>

; Comment 3
; Comment 4"
DefaultGroup="aaa.bbb.ccc"

I saw someone mention the use of the following Jrepl command for this purpose. But nothing seems to happen when I execute the command. Any assistance is greatly appreciated.

Code: Select all

jrepl "^From.*" "NewLine4Here" /jbegln "skip=(ln!=5)" /f "C:\Users\David\Desktop\Test\.gopoststuff1.conf" /o -

You have a simple mistake - that command is skipping the wrong lines. It should be "skip=(ln!=4)"

If you know that only line 4 begins with "From", then you can simply use:

Code: Select all

jrepl "^From.*" "NewLine4Here" /f "C:\Users\David\Desktop\Test\.gopoststuff1.conf" /o -

Or if you want to simply replace line 4, regardless of original content, then

Code: Select all

jrepl "^.*" "NewLine4Here" /jbegln "skip=(ln!=4)" /f "C:\Users\David\Desktop\Test\.gopoststuff1.conf" /o -

JREPL version 4.0 makes the last solution easier:

Code: Select all

jrepl "^.*" "NewLine4Here" /inc 4 /f "C:\Users\David\Desktop\Test\.gopoststuff1.conf" /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

#192 Post by dbenham » 23 Jun 2016 06:34

Here is version 4.1 that greatly improves the help system.

I've added examples to the /T documentation.

And I've made it possible to request help about a single topic or a single option.

For example, the following displays all the options available for HELP

Code: Select all

jrepl /?help

And this displays the new /T documentation

Code: Select all

jrepl /?/t


JREPL.BAT version 4.1
JREPL4.1.zip
(11.51 KiB) Downloaded 898 times


Dave Benham

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

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

#193 Post by foxidrive » 23 Jun 2016 12:46

Nice work.

Code: Select all

  Help is available by supplying a single argument beginning with /?:

      /?        - Writes all available help to stdout.
      /??       - Same as /? except uses MORE for pagination.

      /?Topic   - Writes help about the specified topic to stdout.
                  Valid topics are INTRO, OPTIONS, JSCRIPT, RETURN,
                  VERSION, and HELP

                  Example: List a summary of all available options

                     jrepl /?options

      /?/Option - Writes help about the specified /Option to stdout.

                  Example: Display paged help about the /T option

                     jrepl /??/t

      /?REGEX   - Opens up Microsoft's JScript regular expression
                  documentation within your browser.

      /?REPLACE - Opens up Microsoft's JScript REPLACE documentation
                  within your browser.

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

#194 Post by dbenham » 23 Jun 2016 21:15

Version 4.2 simply improves the documentation for the /?Options summary - it now briefly describes the functionality of each option.

JREPL /?OPTIONS output:

Code: Select all

  Options:  Behavior may be altered by appending one or more options.
  The option names are case insensitive, and may appear in any order
  after the Replace argument.

      /A                     - write Altered lines only
      /B                     - match Beginning of line
      /C                     - Count number of source lines
      /E                     - match End of line
      /EXC LineNumberList    - EXClude one or more lines
      /F InFile              - read from File
      /I                     - Ignore case
      /INC LineNumberList    - Include one or more lines
      /J                     - JScript replace expressions
      /JBEG InitCode         - initialization JScript code
      /JBEGLN NewLineCode    - line initialization JScript code
      /JEND FinalCode        - finalization JScript code
      /JENDLN EndLineCode    - line finalization JScript code
      /JLIB FileList         - load file(s) of initialization code
      /JMATCH                - write matching JScript replacements only
      /L                     - Literal search
      /M                     - Multi-line mode
      /N MinWidth            - prefix output with liNe numbers
      /O OutFile             - write Output to a file
      /OFF MinWidth          - prefix JMatch output with byte OFFsets
      /S VarName             - Source is read from a variable
      /T DelimiterChar       - Translate multiple search/replace pairs
      /V                     - read search/replace/code from Variables
      /X                     - enable eXtended escape sequences


JREPL.BAT version 4.2
JREPL4.2.zip
(11.79 KiB) Downloaded 1015 times


Dave Benham

mirrormirror
Posts: 129
Joined: 08 Feb 2016 20:25

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

#195 Post by mirrormirror » 01 Jul 2016 02:05

Hey guys, I'm cleaning up a couple of older batch scripts and wondered if I might be able to use jRepl or FindRepl to take some bulk out of them. Here are a couple of examples:

1. One routine parses the output from "ipconfig /all" to get the "DNS Servers". I guess there can be 1 or more, in this case there are three:

Code: Select all

   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Thursday, June 30, 2016 12:00P
   Lease Expires . . . . . . . . . . : Sunday, July 03, 2016 12:00P
   Default Gateway . . . . . . . . . : 192.168.0.1
   DHCP Server . . . . . . . . . . . : 192.168.0.1
   DNS Servers . . . . . . . . . . . : 192.168.0.1
                                       184.16.4.22
                                       192.168.88.134
   NetBIOS over Tcpip. . . . . . . . : Disabled
Is there an easy way to put the last DNS server into a variable? And perhaps an alternate version to do the same with the first?

2. I have a wordy routine that parses "Local group Membership" from the "NET USER [User Name]" command. The asterik * causes it to be more complex than I'd like. In the example below, I'd like to parse out all of the group names (those beginning with "*test_").

Code: Select all

F:\>net user user0
User name                    user0
Full Name
Comment                     
User's comment
Country code                 000 (System Default)
Account active               Yes
Account expires              Never

Password last set            6/30/16 9:02p
Password expires             8/11/16 9:02p
Password changeable          6/30/16 9:02p
Password required            Yes
User may change password     Yes

Workstations allowed         All
Logon script
User profile
Home directory
Last logon                   Never

Logon hours allowed          All

Local Group Memberships      *test_et_ro           *test_et_rw
                             *test_t_Links         *test_troot_files
                             *test_sConfigLoc      *test_rs_Temp
                             *test_rs_WAN          *Users
Global Group memberships     *None
The command completed successfully.
Neither of these are pressing needs but as time permits, I'm always looking for better ways to o stuff. So if it is feasible/sensible to use JRepl or FindRepl for these sorts of tasks, I'd appreciate a couple examples to work from.

Thanks :)

Post Reply