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 for removing the form feed for the first match only.
I was trying to play with /p & /pflag "i", but could not get it to work.
I am using the latest version 8.2 of JREPL.BAT.
It is possible to use the JREPL.BAT option
/INCif the first form feed is within a specific block at top of a text file and there is never one more form feed in same block.Example for first form feed within the lines 3 to 10:
The JScript regular expression search string
\fmatches a form feed control character.The replace string is an empty string to remove the form feed in this include block.
The option
/Lfor a literal search cannot be used on using\for alternatively\x0C(hexadecimal value of form feed control character) in search string.The option
/Mcannot be used on using option/INCas explained by help output on running JREPL.BAT in a command prompt window with/?or/??. The lines respectively the line endings must be detected and counted to identify the block from line 3 to line 10 on which the replace should be done and nothing outside this block.A solution using option
/PFLAGis also possible by using:JREPL.BAT runs a JScript regular expression replace with these options searching for a form feed character in entire file because of option
/M. It replaces only first form feed because of using the option/PFLAG ""which means running the case-sensitive replace without flaggfor a non-global replace.But it is necessary to specify also option
/Pwith a regular expression string in addition to the regular expression search string specified as first argument for usage of option/PFLAGwith empty flag string""or with"i"for a non-global case-insensitive search. In this case the additional regular expression after/Pis the same as the main search expression, just\fto match a form feed, the first form feed in entire file.UPDATE:
The real task is to remove in a binary file first and only occurrence of the byte sequence
1B 45and first occurrence of0Cbeing always after1B 45with keeping all other0Cin file. The binary file contains for example beginning at byte offset 752 (hexadecimal 02F0) the bytes:This block should be modified to:
So the task is to remove the two bytes
1B 45at byte offset 761 (hexadecimal 02F9) and the byte0Cat byte offset 912 (hexadecimal 0390) without removing any other byte0Clike the one at byte offset 1011 (hexadecimal 03F3).The following command line can be used in a batch file for removing in such binary files containing ESC+E stored hexadecimal with the bytes
1B 45and first Form Feed stored hexadecimal with the byte0C:The regular expression search string results in searching for
\x1BE... a byte with hexadecimal value1Bfollowed by characterE(case-sensitive) and(...)... with using a marking group[\s\S]... for a whitespace or a non-whitespace character, i.e. any character (or byte)+... one or more times?... non-greedy\f... and a form feed.The bytes between
1B 45and0Cmatched by the expression inside marking group are back-referenced in replace string with$1to be kept in the binary files.