Questions tagged [jrepl]

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
23 questions
0
votes
1 answer

Using JREPL with Special Characters

I am trying to replace the below UninstallPassword="1" with UninstallPassword="0" I am using JREPL.bat and so far can only replace content that does not have special characters. Reading the documentation under /x says I must use /q but I am not…
David
  • 127
  • 3
  • 10
0
votes
1 answer

JREPL.bat regex replacing inside quotes

Im using JREPL.BAT to find and replace specific instances and my regex I have works for find and replace in VSC code and also in the couple regex editors I've used. CALL ./framework/config/JREPL.BAT "(Error)+\(([^()]*|\(([^()]*|\([^()]*\))*\))*\)"…
Derek Lawrence
  • 1,551
  • 2
  • 16
  • 36
0
votes
0 answers

JREPL.BAT - regex to remove lines in file

I have a source data file which I have been using JREPL.BAT to perform some very simple search and replace operations quite successfully. I now need to expand on that to do 2 jobs. 1. remove all lines that start with the string "appX_formContent".…
zoomzoomvince
  • 239
  • 1
  • 5
  • 14
0
votes
2 answers

how to replace one line in text file without removing empty lines in batch

i am trying to code a simple script in batch that can find and replace a line so far, I've found a snippet that works perfectly fine for my purpose the only problem is that it removes empty lines and i can't figure out why!! I've tried to add…
abdelhamied mostafa
  • 215
  • 1
  • 3
  • 14
0
votes
1 answer

JREPL Replace Values in One Column Only in a CSV

I am using JREPL (which is a very fast tool by the way) to search through a large CSV file and then replace some text in the file. However I ma running into a problem, whereby I only want to replace the values in the very first column of my file,…
Matthew Colley
  • 10,816
  • 9
  • 43
  • 63
0
votes
1 answer

Replace control character with JREPL.bat

I am trying to replace the text 'HEADER' within a file with the control character new page (FF - Hex value = C). I was able to do this using SED as shown below: sed -I "s/HEADER/\xC/g" c:\myfile.txt I want to be able to do this using JREPL.BAT. I…
Ezy
  • 17
  • 6
0
votes
1 answer

Need to insert a column in csv and parse current date in it - JREPL.BAT?

I could (thanks to dbenham and its powerful JREPL.BAT) remove header row from CSV File with command jrepl "^(Date,)?.*" "($1?i++:i)?$0:false" /jmatch /jbeg "var i=0" /f test.txt /o output.txt I now need to insert in this csv below the date in…
R_life_R
  • 786
  • 6
  • 26
-1
votes
1 answer

Why does JREPL.bat close my batch script?

Here's a bit of a problem I'm having with JREPL.bat. Whenever I use JREPL in a batch script, it completely shuts down my batch session after running the command. It still replaces text like it's supposed to. But it still closes. Here's the…
1
2