Questions about JREPL.BAT - A regular expression text processing utility for the Windows command line.
JREPL.BAT is a free regular expression text processing utility for the Windows command line. It is pure script written as hybrid batch/JScript that runs natively on any Windows machine from XP onward - no 3rd party exe or dll required.
The following trivial example will substitute blue
for all instances of the word red
in file test.txt
jrepl "\bred\b" "blue" /f test.txt /o -
The utility is available at DosTips - https://www.dostips.com/forum/viewtopic.php?t=6044. Within that large thread you can trace the full development history, as well as find many examples on how to use it.
Included in the first post is an index to all the different releases, including the features added with each version. If you have a question about a particular option, then find the version that introduced the option and go to that release. Typically you will find examples and or explanations on how to use the new features.
One of the most important features of JREPL is the extensive built in help. Use jrepl /?help
to get an explanation of all types of help available
>jrepl /?help
Help is available by supplying a single argument beginning with /? or /??:
/? - 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 - Basic syntax and default behavior
OPTIONS - Brief summary of all options
JSCRIPT - JREPL objects available to user JScript
RETURN - All possible return codes
VERSION - Display the version of JREPL.BAT
HISTORY - A summary of all releases
HELP - Lists all methods of getting help
Example: List a summary of all available options
jrepl /?options
/?WebTopic - Opens up a web page within your browser about a topic.
Valid web topics are:
REGEX - Microsoft regular expression documentation
REPLACE - Microsoft Replace method documentation
UPDATE - DosTips release page for JREPL.BAT
CHARSET - List of possible character set names for ADO I/O
Some character sets may not be installed
XREGEXP - xRegExp.com home page (extended regex docs)
/?/Option - Writes detailed help about the specified /Option to stdout.
Example: Display paged help about the /T option
jrepl /??/t
/?CHARSET/[Query] - List all character set names for use with ADO I/O
that are installed on this computer. Optionally restrict
the list to names that contain Query. Wildcards * and ? may
be used within Query. The default Query is an empty string,
meaning list all available character sets. The list is
generated via reg.exe.
Examples:
jrepl /??charset/ - Paged list of all available names
jrepl /?charset/utf - List of names containing "utf"
Below is the INTRO section of the help that describes the basic syntax
>jrepl /?intro
JREPL Search Replace [/Option [Value]]...
JREPL /?[?][Topic|/Option|CHARSET/[Query]|HELP]
Perform a global regular expression search and replace operation on
each line of ASCII input from stdin and prints the result to stdout.
Each parameter may be optionally enclosed by double quotes. The double
quotes are not considered part of the argument. The quotes are required
if the parameter contains a batch token delimiter like space, tab, comma,
semicolon. The quotes should also be used if the argument contains a
batch special character like &, |, etc. so that the special character
does not need to be escaped with ^.
Search - By default, this is a case sensitive JScript (ECMA) regular
expression expressed as a string.
JScript regex syntax documentation is available at
https://msdn.microsoft.com/en-us/library/ae5bf541.aspx
Replace - By default, this is the string to be used as a replacement for
each found search expression. Full support is provided for
substitution patterns available to the JScript replace method.
For example, $& represents the portion of the source that matched
the entire search pattern, $1 represents the first captured
submatch, $2 the second captured submatch, etc. A $ literal
can be escaped as $$.
An empty replacement string must be represented as "".
Replace substitution pattern syntax is fully documented at
https://msdn.microsoft.com/en-US/library/efy6s3e6.aspx
Binary input with NULL bytes requires either the /M option, or the file
must be read using ADO by appending the character set name to the file name.
For example, if your input is ASCII containing null bytes, then you must
use: /F "input.txt" /M or /F "input.txt|ascii".
The meaning of extended ASCII byte codes >= 128 (0x80) is dependent on the
active code page. Extended ASCII within arguments and variables may require
the /XFILE option.
Lastly, here is a quick summary of all options available to JREPL.BAT version 8.5. Be sure to look at the detailed help for any given option for a complete explanation. For example jrepl /?/t
will give the full help for the /T
option.
>jrepl /?options
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
/APP - Append results to the output file
/B - match Beginning of line
/C - Count number of source lines
/D - Delimiter for /N and /OFF
/E - match End of line
/EOL EndOfLineString - set the End Of Line terminator
/EXC BlockList - EXClude lines from selected blocks
/F InFile[|CharSet[|NB]]- read input from a File
/H - Highlight replaced or matched text
/HON HilightStart - defines the string to start highlighting
/HOFF HilightEnd - defines the string to stop highlighting
/HU - Underline replaced or matched text
/I - Ignore case
/INC BlockList - INClude lines from selected blocks
/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
/JMATCHQ - new Quick form of /JMATCH
/JQ - new Quick form of /J
/K Context or Pre:Post - search and Keep lines that match
/L - Literal search
/M - Multi-line mode
/MATCH - Search and print each match, one per line
/N MinWidth - prefix output with liNe numbers
/O OutFile[|CharSet[|NB]]- write Output to a file
/OFF MinWidth - add OFFsets to /K, /JMATCHQ, /MATCH output
/P Regex - only search/replace strings that match a Regex
/PFLAG Flags - set the /P regex Flags to "g", "gi", "" or "i"
/PREPL FilterReplCode - selectively Search/Replace captured /P groups
/R Context or Pre:Post - search and Reject lines that match
/RTN ReturnVar[:Line#] - Return result in a variable
/S VarName - Source is read from a variable
/T DelimChar or FILE - Translate multiple search/replace pairs
/TFLAG Flags - specify XRegExp flags for use with /T
/U - Unix line terminators (\n instead of \r\n)
/UTF - all input and output as UTF-16LE (BOM optional)
/V - use Variables for Search/Replace and code
/VT - enable Virtual Terminal ANSI escape sequences
/X - shorthand for combined /XFILE and /XSEQ
/XBYTES - force creation of new XBYTES.DAT
/XBYTESOFF - force /XSEQ \xnn to be treated as Windows-1252
/XFILE - preserve extended ASCII in args via temp files
/XREG FileList - adds XRegExp support to JREPL
/XSEQ - enable extended escape sequences