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
1
vote
0 answers

JREPL.BAT - Having issues with /INC and a string with a unicode symbol

I have a string that i'm using as a [START] position within a /INC. This string has a unicode symbol. This unicode symbol appears to NOT be getting read by JREPL. My output file ends up blank until I remove the symbol and retry. Is there any way…
Paul
  • 11
  • 5
1
vote
2 answers

Batch script. Handling strings with CR line endings

I decided to reformat my question due to comments of users (thanks to all) and new knowledge I have got. I'll not open a new post because the main problem remains the same: How to handle strings produced by some program (e.g. CURL) line-by-line…
user1581016
  • 61
  • 1
  • 8
1
vote
1 answer

How to replace + append with jrepl via cmd?

In Windows, I have a batch file for processing the text file C:\BBB\CCC\list.txt for deciding which files to move. It should move all the files that are in a folder (%folder%) and its subfolders, but only if: in the name of the folder there is not…
solquest
  • 65
  • 10
1
vote
2 answers

JREPL to match URL that contains keyword

I am trying to use JREPL.bat to match URLs containing a specific term in a txt file (and then write the result back to the file). This is what I have so far, unfortunately it is not returning the expected result. The result is always NULL: JREPL.bat…
khofm
  • 139
  • 4
1
vote
1 answer

Replace text in file using JREPL.BAT

My batch script is supposed to replace content within a file or list of files, but doesn't work and unfortunately exits cycle loop... Here the code: @echo off setlocal enabledelayedexpansion set "int=000" set "int_new=111" for %%i in ("c:\text.txt")…
1
vote
1 answer

How to replace only the first match in a text file with jrepl using /pflag "i" switch?

I am trying to replace only the first match in a text file. My code is: FOR /R %%a IN ("*.out") DO call C:\qsi\jrepl.bat "FF**********" "**********" /f "%%a" /L /m /o - The FF before the asterisks is representing a form feed character. The code is…
1
vote
1 answer

Changing a line in a cfg file with a batch file

I'm on Windows, trying to use the following batch file: @echo off &setlocal set "search=false); // disable U" set "replace=true); // disable U" set "textfile=C:\Program Files (x86)\Mozilla Firefox\mozilla.cfg" call jrepl.bat "%search%" "%replace%"…
1
vote
1 answer

modify the found text using batch file

Firstly, I am looking for something different from this: Batch / Find And Edit Lines in TXT file My purpose is modify the "fillColor="#242838" with fillColor="mycolor" However, the hex color in this statement can be anything like…
ziLk
  • 3,120
  • 21
  • 45
1
vote
2 answers

remove thousand separator of number in CSV (batch command, using JREPL)

I have the following csv where I have to replace the thousand comma separator with nothing. In example below, when I have the amount "1,000.00" I should have 1000.00 (no comma, no quotes) instead. I use JREPL to remove header from my csv jrepl…
R_life_R
  • 786
  • 6
  • 26
1
vote
2 answers

Renaming file which is contain Ö ö Ç ç Ş ş İ ı Ğ ğ Ü ü

I am trying to rename files with batch. I want to replace letters Ö ö Ç ç Ş ş İ ı Ğ ğ Ü ü with O o C c S s I i G g U u but its failing. What can i do for fix this problem. @echo OFF set TargetFolder=%~dp0target setlocal enableDelayedExpansion set…
John DOE
  • 400
  • 1
  • 3
  • 18
0
votes
1 answer

How to use the /M option in JREPL.BAT to get strings across multiple lines?

I want to get all strings between and that spands across multiple lines. The amount of lines between is not always the same. Can anyone help? Throttle up and take to the skies in this radar-evading advanced…
Paul
  • 11
  • 5
0
votes
1 answer

jrepl.bat: can't seem to get syntax correct

During the course of a batch file, a path like the following is stored in temp.txt: c:\folder1\folder2\. The period at the end is just because the path is generated from a for /r %%a in (.) statement. I try to get rid of this using the world famous…
fortissimo
  • 51
  • 8
0
votes
1 answer

Request for help to speed up batch program for 17,000 TXT files

I have over 17,000 pages that have been scanned (for a local history archive) which I have OCRed using Tesseract to individual TXT files. I want to be able to search/locate every page containing a search word of more than 3, lower case letters. So…
John
  • 1
  • 2
0
votes
1 answer

The specified installation folder is read-only Netbeans error message

I am trying to install Netbeans latest version. And I can't pass through this error "The specified installation folder is read-only" when it asks for "JDK for Netbeans IDE". I've tried manually unchecked the Read-only check in Program…
0
votes
1 answer

jrepl - how to print out only first modified line

I have several lines text file and would like to get only the first line that is modified. For example I have the follow text file and would like to get the ID number: something 1 is written here My ID 1234 for file A something 2 is written here My…
audi02
  • 559
  • 1
  • 4
  • 16
1
2