1.

Solve : find some words and add a word after them in batch script?

Answer»

I have a txt files in a FOLDER. I want a batch script which

   - goes to that directory and
   - in that file it looks and insert “timestamp” for whatever comes after "AAA" or "BBB" and before "{".

Example:
AAA mmmmmmmmmm {

After running the script: AAA mmmmmmmmmm_timestamp {

how can I do it? any suggestion?I'd look into using the helper program repl.bat.  I'm going to SEE if I can figure it out past that.God Bless the DOS Helpers...
They get no respect for answering some of the queerist questions onboard...

Kudos to you guys.... Quote from: Lemonilla on September 02, 2014, 05:31:16 PM

I'd look into using the helper program repl.bat.  I'm going to see if I can figure it out past that.

How did you go Lemonilla?  I was going to let this question slide coz it hasn't got enough info
but now that you've mentioned repl.bat I also had a CRACK at it.

Code: [Select]echo off
type "file.txt" | repl "(.*)(AAA|BBB)(.*)({.*)" "$1$2$3timestamp$4"
pause


file.txt
AAA mmmmmmmmmm {aaa

BBB mmmmmmmmmm {bbb

ZAAA mmmmmmmmmm {ccc

ZBBB mmmmmmmmmm {ddd


and the output:

AAA mmmmmmmmmm timestamp{aaa

BBB mmmmmmmmmm timestamp{bbb

ZAAA mmmmmmmmmm timestamp{ccc

ZBBB mmmmmmmmmm timestamp{ddd


This uses a helper batch file called `repl.bat` (by dbenham) - download from:  https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
Thanks Foxidrive, I tried * for the wildcard, but it didn't seem to do anything.  From you're code it looks like (.*) is the wildcard? Quote from: Lemonilla on September 03, 2014, 02:53:23 PM
From you're code it looks like (.*) is the wildcard?
That is common syntax for most programs that do regular expressions.  Many of them are very similar.
The parenthesis are a GROUPING.  The period matches any character.  The asterisk matches zero or more OCCURRENCES of the previous character.


Discussion

No Comment Found