JREPL.BAT v8.6 - regex text processor with support for text highlighting and alternate character sets
Moderator: DosItHelp
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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.
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.
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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:
From within a batch script:
Dave Benham
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
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
@dbenham thanks a lot for your support...much respect...
_
works perfect from command-line prompt...
_
works perfect from a .bat file!
_
_
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!
_
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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.
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.
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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:REPL.BAT is incompatible with accents or I missed something ?
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
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
It works, thank you penpen
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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:
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
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
-
- Posts: 4
- Joined: 18 Jun 2016 21:21
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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:
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.
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 -
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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.
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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:
To accomplish the same thing with version 3.8 (this also works in 4.0, but is less convenient):
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
Dave Benham
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
Dave Benham
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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
And this displays the new /T documentation
JREPL.BAT version 4.1
Dave Benham
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
Dave Benham
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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.
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Version 4.2 simply improves the documentation for the /?Options summary - it now briefly describes the functionality of each option.
JREPL /?OPTIONS output:
JREPL.BAT version 4.2
Dave Benham
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
Dave Benham
-
- Posts: 129
- Joined: 08 Feb 2016 20:25
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
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:
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_").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
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
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.
Thanks