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
I found my first bug in v6.3 - I forgot to negate the result of the /EXC tests, so it was giving me an inverted result.
I fixed the bug and updated the prior post to v6.4.
Dave Benham
I fixed the bug and updated the prior post to v6.4.
Dave Benham
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Hi Dave,
Awesome work,
I am able to get the very basics of this working but I am by no means advanced enough to get what I am looking for to work.
I am wondering if it is possible to take multiple pieces of data from one xml and repopulate the tags in another xml. The catch is though that there is multiple tags in the same file with the same name.
Thank you for any help,
Jon.
Awesome work,
I am able to get the very basics of this working but I am by no means advanced enough to get what I am looking for to work.
I am wondering if it is possible to take multiple pieces of data from one xml and repopulate the tags in another xml. The catch is though that there is multiple tags in the same file with the same name.
Code: Select all
<example id="[b]aaa[/b]">
<source id="0">
<name>[b]bbb[/b]</name>
<location>[b]ccc[/b]</location>
</source>
<size value="[b]ddd[/b]" />
</example>
<example id="[b]eee[/b]">
<source id="1">
<name>[b]fff[/b]</name>
<location>[b]ggg[/b]</location>
</source>
<size value="[b]hhh[/b]" />
</example>
<example id="[b]iii[/b]">
<source id="2">
<name>[b]jjj[/b]</name>
<location>[b]kkk[/b]</location>
</source>
<size value="[b]lll[/b]" />
</example>
Thank you for any help,
Jon.
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Regardless what your full requirements are, you really should use a tool designed to work with XML. The way you describe your problem, it sounds like a classic transformation problem for XSLT.
That being said, it might be possible with JREPL if you make a number of assumptions about the physical layout of your XML files (usually a bad idea). Unless I am misinterpreting your goal, I can almost guarantee it would require a fair amount of user supplied JScript, and I'm thinking you would be driving a nail with a screwdriver.
You haven't provided nearly enough information to begin to solve your problem with any tool. When you say "repopulate the tags in another xml", I can't tell if you are talking about merging two existing XML documents, or if your are building the second one from scratch based on the content of the first. You would have to provide a lot more details about the before and after documents.
I strongly encourage you to consider a true XML processing tool.
Dave Benham
That being said, it might be possible with JREPL if you make a number of assumptions about the physical layout of your XML files (usually a bad idea). Unless I am misinterpreting your goal, I can almost guarantee it would require a fair amount of user supplied JScript, and I'm thinking you would be driving a nail with a screwdriver.
You haven't provided nearly enough information to begin to solve your problem with any tool. When you say "repopulate the tags in another xml", I can't tell if you are talking about merging two existing XML documents, or if your are building the second one from scratch based on the content of the first. You would have to provide a lot more details about the before and after documents.
I strongly encourage you to consider a true XML processing tool.
Dave Benham
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Hi Dave,
Thanks for the reply.
Sorry for not being very clear. I have two XML files both with information in, in the same structure.
What I am looking to do is replace the data in some of the tags on one XML file with data from the other XML file.
If it's not easy to do, I'll looking into using a proper XML editing tool as you say.
Thanks,
Jon.
Thanks for the reply.
Sorry for not being very clear. I have two XML files both with information in, in the same structure.
What I am looking to do is replace the data in some of the tags on one XML file with data from the other XML file.
If it's not easy to do, I'll looking into using a proper XML editing tool as you say.
Thanks,
Jon.
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Jon wrote:Hi Dave,
Thanks for the reply.
Sorry for not being very clear. I have two XML files both with information in, in the same structure.
What I am looking to do is replace the data in some of the tags on one XML file with data from the other XML file.
If it's not easy to do, I'll looking into using a proper XML editing tool as you say.
Thanks,
Jon.
Without providing some clear verifiable examples it is hard to code anything at this point. We can probably give you an XML solution as well because we do have people here who use Vbscript and Jscript and both of those scripting languages have XML capability. But you need to provide more information before anyone can help you.
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Jon
It's Batch that can't handle XML properly. Even regex as Dave uses in his tool can't handle XML properly. It's not a big deal to write a hybrid script to solve your problem, see ...
viewtopic.php?f=3&t=7296
... but we would have to know the the entire structure of these XML files, beginning with the declaration <?XML ...
Since that would be pretty off topic in this thread I'd suggest you to create a new topic where you can provide the missing information.
Steffen
It's Batch that can't handle XML properly. Even regex as Dave uses in his tool can't handle XML properly. It's not a big deal to write a hybrid script to solve your problem, see ...
viewtopic.php?f=3&t=7296
... but we would have to know the the entire structure of these XML files, beginning with the declaration <?XML ...
Since that would be pretty off topic in this thread I'd suggest you to create a new topic where you can provide the missing information.
Steffen
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
JREPL version 6.6 introduces one new feature, refines another, and corrects a documentation error:
1) New /RTN option writes the result to an environment variable instead of stdout or a file. The entire result must fit within a single variable, else the command will fail. This option can be used with any combination of options, but it is probably most useful with /MATCH, /JMATCH, or /JMATCHQ if input is stdin or a file. This option is also an excellent way to manipulate the content of an existing variable if combined with /S and /M.
Output is first written to a temporary file within %TEMP%, and then it is read back in and stored in the variable, and the temp file is deleted.
The /RTN option is nearly useless if JREPL is used with a pipe because piped commands run within a new command shell process, and any variables defined within that process will be undefined as soon as the pipe terminates.
Here is the full documentation:
Code: Select all
>jrepl /?/rtn
/RTN ReturnVar[:[-]LineNumber]
Write the result to variable ReturnVar.
If the optional LineNumber is present, then only that specified
line within the result set is returned. A LineNumber of 1 is the
first line. A negative LineNumber is measured from the end of the
result set, so -1 is the last line.
All byte codes except NULL (0x00) are preserved, regardless
whether delayed expansion is enabled or not. An error is thrown
and no value stored if the result contains NULL.
An error is thrown and no value stored if the value does not fit
within a variable. The maximum returned length varies depending
on the variable name and result content. The longest possible
returned length is 8179 bytes.
The line terminator of the last match is suppressed if /MATCH,
/JMATCH, or /JMATCHQ is used.
Example 1: Store the last word of input.txt in variable lastWord.
Code: Select all
call jrepl \S+ "" /match /f input.txt /rtn lastWord:-1
Example 2: Substitute : for all = characters within variable var (very difficult task with pure batch).
Code: Select all
call jrepl "=" ":" /m /s var /rtn var
2) Provide consistent support for extended ASCII when /X is used
JREPL was designed to primarily work with 7bit ASCII. However, it has always had limited support for high order bytes (extended ASCII). Byte codes >= 128 (0x80) were preserved when they appeared in stdin, input files, and/or output files. However, prior versions of JREPL did not properly read extended ASCII within command line parameters or variables. The only recourse was to use the \xnn string literal escape sequence, and /X was required to get the correct interpretation.
Version 6.5 modifies the behavior of /X so that command line arguments and variables are automatically written to temporary files within %TEMP%, where the extended ASCII string literals can be read properly. The temporary files are deleted once the command completes.
Now JREPL with /X will work properly with extended ASCII literals no matter where they apper. Note that environment variables actually store strings as UTF-16. It is possible that a variable may have a character that does not map to the current active code page, in which case batch will automatically convert it into a ? character. So care should be taken to make sure that all your content fits within the active code page.
3) Documentation correction
Version 6.0 introduced a documentation error regarding return codes. It improperly listed return codes of 0, 1, 3, and 4. The error persisted through version 6.5.
This version 6.6 fixes the documentation error and properly lists return codes 0, 1, 2, and 3.
Dave Benham
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
I've replaced version 6.5 with 6.6 in the previous post. The only difference is a correction to the documentation on return codes.
Dave Benham
Dave Benham
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
dbenham wrote:Example 1: Store the last word of input.txt in variable lastWord.Code: Select all
call jrepl \s+ "" /match /f input.txt /rtn lastWord:-1
'\s' should be '\S' (upper case).
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Of course it should
I've edited the post to fix that mistake. Thanks Mike D.
Dave Benham
I've edited the post to fix that mistake. Thanks Mike D.
Dave Benham
-
- Posts: 4
- Joined: 18 Jun 2016 21:21
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
I'm new to JREPL.bat.
Hoping to replace a particular line in a text file. I'm currently using the following command to replace line 3 with the text abc123
jrepl "^.*" "abc123" /inc 3 /f "C:\test.txt" /o -
It works at the moment. However, if I wanted to replace line 3 with "abc123" (i.e. line 3 should also have quotation marks around abc123), any ideas how to do it?
Hoping to replace a particular line in a text file. I'm currently using the following command to replace line 3 with the text abc123
jrepl "^.*" "abc123" /inc 3 /f "C:\test.txt" /o -
It works at the moment. However, if I wanted to replace line 3 with "abc123" (i.e. line 3 should also have quotation marks around abc123), any ideas how to do it?
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Did you look at the /X option.
-
- Posts: 4
- Joined: 18 Jun 2016 21:21
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
Squashman wrote:Did you look at the /X option.
I'm not too sure how does the /X option work?
jrepl "^.*" "abc123" /inc 3 /f "C:\test.txt" /o - /X \q
Says there are too many arguments
-
- Posts: 4
- Joined: 18 Jun 2016 21:21
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
bluesky088 wrote:Squashman wrote:Did you look at the /X option.
I'm not too sure how does the /X option work?
jrepl "^.*" "abc123" /inc 3 /f "C:\test.txt" /o - /X \q
Says there are too many arguments
Figured it out:
jrepl "^.*" "\qabc123\q" /inc 3 /f "C:\test.txt" /o - /X
This works now. thanks
Re: JREPL.BAT - regex text processor - successor to REPL.BAT
@dbenham
i have this text file:
can i use this tool (in a .bat) to insert a new line (hex sequence 0x0d0a) before START and after END in one ore more steps?
_
i have this text file:
Code: Select all
somerandomblablablaSTARTmorerandomblablablaENDlastrandomblablabla
can i use this tool (in a .bat) to insert a new line (hex sequence 0x0d0a) before START and after END in one ore more steps?
_