Page 2 of 10

Re: New regex utility to search and replace strings in files

Posted: 02 Jul 2013 06:52
by brinda
Antonio,

Thanks again for helping. I am putting the partial file which is used below.

test.txt

Code: Select all

Mainframe ID T03 -412
Check V = 5
Check End = 9

Mainframe ID T04 -412
     Rohm = 1.51
     Pwr = 7.42
     Amp = 0.95
     Cap = - 8.78
     Bpwr = 588.24
     Bchr = 6.358
     Spwr = 90
Check voltage is 415.67

Mainframe ID T05 -412
Power dist : 0
Vdd = 0
Vcal = 0


On the old findrepl using /O:-7:-1(to replace findstr). To convert vertical data to horizontal for ease or comparing this command [findrepl "\r\n" "" ] is used

This gives me a horizontal data from vertical like below.

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 | findrepl "\r\n" ""
     Rohm = 1.51     Pwr = 7.42     Amp = 0.95     Cap = - 8.78     Bpwr = 588.24     Bchr = 6.358     Spwr = 90


on using the command below with the new script, It seems to copy everything

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 /B:"\r\n" ""
Asigno removeCRLF: [\r\n] vs [\n\r]
Replace: procBlocks=true, removeCRLF = false
Mainframe ID T03 -412
Check V = 5
Check End = 9

Mainframe ID T04 -412
Replace + procBlocks + inRange, removeCRLF = false
     Rohm = 1.51
     Pwr = 7.42
     Amp = 0.95
     Cap = - 8.78
     Bpwr = 588.24
     Bchr = 6.358
     Spwr = 90
Check voltage is 415.67

Mainframe ID T05 -412
Power dist : 0
Vdd = 0
Vcal = 00


This method works with the new findrepl but it adds new character

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 | findrepl "\r\n" ""
Asigno removeCRLF: [undefined] vs [\n\r]
     Rohm = 1.51     Pwr = 7.42     Amp = 0.95     Cap = - 8.78     Bpwr = 588.24     Bchr = 6.358     Spwr = 90


thanks again for helping. :)

Re: New regex utility to search and replace strings in files

Posted: 02 Jul 2013 09:33
by Aacini
Oops! I was really tired last night! :shock: It seems that I deleted last program version and posted a previous one with tracing .Echo's. I apologize. :oops: I just posted the good new version above...

I also "forgot" to indicate that you must include the new /VR switch this way:

Code: Select all

for %%g IN (*%%f_LN*) do (
< "%%g" ..\findrepl  "Check Voltage is" /O:-7:-1 /B:"\r\n" "" /VR >> ..\test.htm
)

Perhaps you want to do a couple tests with and without /VR switch and check the differences...

Antonio

Re: New regex utility to search and replace strings in files

Posted: 03 Jul 2013 06:32
by brinda
Antonio,
Thanks and sorry to trouble again :( . Copied the latest script on Page 1 but there is no output on using /VR.

with /VR

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 /B"\r\n" "" /VR

D:\>


without /VR it copies as before

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 /B"\r\n" ""
Mainframe ID T03 -412
Check V = 5
Check End = 9

Mainframe ID T04 -412
     Rohm = 1.51
     Pwr = 7.42
     Amp = 0.95
     Cap = - 8.78
     Bpwr = 588.24
     Bchr = 6.358
     Spwr = 90
Check voltage is 415.67

Mainframe ID T05 -412
Power dist : 0
Vdd = 0
Vcal = 0

D:\>


this command still works as in the first script without comment

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 | findrepl "\r\n" ""
     Rohm = 1.51     Pwr = 7.42     Amp = 0.95     Cap = - 8.78     Bpwr = 588.24     Bchr = 6.358     Spwr = 90


I tested this script on actual logs and it outputs the same as the example. Thanks for looking.

Re: New regex utility to search and replace strings in files

Posted: 03 Jul 2013 07:34
by Aacini
You missed a colon in /B:"\r\n" switch!

Aacini wrote:The colons in all switches are mandatory.


I apologize about this point, but this is the way that "named arguments" works in JScript programs...

Antonio

Re: New regex utility to search and replace strings in files

Posted: 03 Jul 2013 07:50
by brinda
Antonio,
syntax is ok, it replaces grep - that is great. No issue..

my fault. sorry :oops:

I made 2 tries but copied the separate one.

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 /B:"\r\n" ""
Mainframe ID T03 -412
Check V = 5
Check End = 9

Mainframe ID T04 -412
     Rohm = 1.51
     Pwr = 7.42
     Amp = 0.95
     Cap = - 8.78
     Bpwr = 588.24
     Bchr = 6.358
     Spwr = 90
Check voltage is 415.67

Mainframe ID T05 -412
Power dist : 0
Vdd = 0
Vcal = 0

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 /B:"\r\n" "" /VR

D:\>


using win2000 SP4

Re: New regex utility to search and replace strings in files

Posted: 03 Jul 2013 08:02
by brinda
Antonio,

Having a space after B: gives vertical output. just found. posting partial below

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 /B: "\r\n" "" /VR

R
o
h
m

=

1
.
5
1







P
w
r

=

7
.
4
2



Re: New regex utility to search and replace strings in files

Posted: 03 Jul 2013 08:05
by Aacini
Wow! My fault :shock: :cry: :oops:

The line # 153 of the program is this:

Code: Select all

   removeCRLF = (block == "\\n\\r") && (replace == "");

Just interchange the \\n and \\r this way:

Code: Select all

   removeCRLF = (block == "\\r\\n") && (replace == "");


................................

Re: New regex utility to search and replace strings in files

Posted: 03 Jul 2013 08:16
by brinda
Antonio,

Thank you so much for spending your time on this s :D :D :D learnt a lot today

Code: Select all

D:\>< test.txt findrepl "Check voltage is" /O:-7:-1 /B:"\r\n" "" /VR
     Rohm = 1.51     Pwr = 7.42     Amp = 0.95     Cap = - 8.78     Bpwr = 588.2
4     Bchr = 6.358     Spwr = 90


All working. now to go and ammend this wonderful method to the other batch file.

thanks so much.

Re: New regex utility to search and replace strings in files

Posted: 06 Jul 2013 21:25
by Aacini
I changed the /VR switch by just /R. :? I think it is clearer this way (I don't know why I didn't used /R in first place).

Antonio

Re: New regex utility to search and replace strings in files

Posted: 08 Oct 2013 02:57
by foxidrive
I have a query regarding the regular expression syntax

I have a list of words and I want to print the words that contain any combination of a set of letters.

I can do the opposite by this: type wordlist.txt | findrepl /v "[atp]" and words containing a or t or p will be excluded,

If I want to only include words that contain a t e p r s such as pepper then how can I do that?

Re: New regex utility to search and replace strings in files

Posted: 08 Oct 2013 06:44
by dbenham
Assuming you have one word per line, I believe this should work:

Code: Select all

type wordlist.txt | findrepl "^[ateprs]+$"

A similar search should work with FINDSTR as well

Code: Select all

type wordlist.txt | findstr "^[ateprs][ateprs]*$"


Dave Benham

Re: New regex utility to search and replace strings in files

Posted: 08 Oct 2013 06:53
by foxidrive
They work well Dave, ta.

I always find it easier after seeing an example. Both findrepl and findstr work in this example with this regexp too "^[ateprs]*$"

Re: New regex utility to search and replace strings in files

Posted: 08 Oct 2013 10:19
by dbenham
Almost identical, except that regex will also match an empty line. The solutions I posted require at least one valid character.

Dave

Re: New regex utility to search and replace strings in files

Posted: 05 Apr 2014 07:25
by Squashman
Aacini, can you please look into a couple of issues I've noticed?

Issue 1) Findrepl hangs when searching a folder full of files, when it contains various images. Here is an example:

Image from https://github.global.ssl.fastly.net/im ... ws-app.png

code sample follows that demonstrates the issue in Windows 8.1:

Code: Select all

findrepl /i cat <gh-windows-app.png



Issue 2) Findrepl generates a harmless but annoying error if a file to be searched is zero bytes

Thanks

Re: New regex utility to search and replace strings in files

Posted: 06 Apr 2014 09:54
by Aacini
@Squashman,

Well, findrepl is designed to work on text files. Although I don't see any reason because it hangs on a binary file (excepting its size, perhaps), it is necessary to do some tests. It would be easier to filter the files that will be processed...

The same point apply to empty files. I will test these points when I have any spare time.

Antonio