Return total number of found strings using JREPL

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Return total number of found strings using JREPL

#1 Post by SIMMS7400 » 09 Aug 2016 07:54

Good Morning D -

I'm using JREPL.bat file and complimenting code to search a set of import files for a specific string.

Here is the code I am using:

Code: Select all

@echo off
setlocal

for %%F in (*.txt) do (
  set "file=%%F"
  jrepl " 0 " "cnt+=1; false" /l /jmatch /jbeg "cnt=0" /jend "if (cnt) output.WriteLine(lpad(cnt,'         ')+env('file'))" /f "%%F">>C:\OUTPUT.txt

)


It returns the following :

4C1.txt
4C2.txt
4C3.txt


Is there anyway to also return the total number? I have dozens of files and a total amount as well would be extremely beneficial.

Thank you!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Return total number of found strings using JREPL

#2 Post by foxidrive » 09 Aug 2016 09:54

SIMMS7400 wrote:Good Morning D -

I'm using JREPL.bat file and complimenting code to search a set of import files for a specific string.

Here is the code I am using:

Code: Select all

@echo off
setlocal

for %%F in (*.txt) do (
  set "file=%%F"
  jrepl " 0 " "cnt+=1; false" /l /jmatch /jbeg "cnt=0" /jend "if (cnt) output.WriteLine(lpad(cnt,'         ')+env('file'))" /f "%%F">>C:\OUTPUT.txt

)


It returns the following :

4C1.txt
4C2.txt
4C3.txt


Is there anyway to also return the total number? I have dozens of files and a total amount as well would be extremely beneficial.

Thank you!


What do your input filenames look like? What is that code doing to them?

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Return total number of found strings using JREPL

#3 Post by dbenham » 09 Aug 2016 19:19

Why are you making life so difficult? I'm all for using JScript with JREPL, but I don't see the point in this case. Here is how I would solve the problem. Note that I did not bother left padding the numbers, and I added a space between each count and the file name. Padding could be added easily enough if it is really needed.

Code: Select all

@echo off
setlocal

set /a total=0
>c:\output.txt (
   for %%F in (*.txt) do for /f %%N in (
     'jrepl " 0 " 'x' /l /jmatch /f "%%F" ^| find /c /v ""'
   ) do (
    echo %%N %%F
    set /a total+=%%N
  )
  echo(
  call echo Total %%total%%
)


Dave Benham
Last edited by dbenham on 10 Aug 2016 04:40, edited 1 time in total.

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Return total number of found strings using JREPL

#4 Post by SIMMS7400 » 10 Aug 2016 04:31

Thank you, Dave!

I just tried to test this and I'm getting a JScript error:

JScript run time error in replace code: 'x' is undefined.

Thanks!

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Return total number of found strings using JREPL

#5 Post by dbenham » 10 Aug 2016 04:42

Oops :oops:

I forgot the single quotes around the x string constant. I've edited the code in my prior post.


Dave Benham

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Return total number of found strings using JREPL

#6 Post by SIMMS7400 » 10 Aug 2016 06:56

Dave -

Works like a charm!! Thank you!

It's amazing how much slower DOS is compared to Shell.

For instance, I'm running this script over 12 files equaling about 24gigs. It takes approx 1.5 hours. With shell, it completes the same data set in about 15 minutes. I wish there was a way to speed things up.

Oh the life of DOSSSSSSS.

Thank you, again!

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Return total number of found strings using JREPL

#7 Post by SIMMS7400 » 10 Aug 2016 08:04

HI Dave -

I have one additional requirement. If we can't incorpoate it into this logic, no worries. I can forumulate another method.

In any case, aside from number of return strings per file and overall total (the latest version of the script above) I'd also like to find the total number of records.

In my data files, the last 12 columns are always data columns. Here is a small portion of a data file:

CP_NA,PL_NA,DS_INPUT,ACT,FIN,FY16,CO_8304,CC_8180,AC_402000,0.00,0.00,-100000.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
CP_NA,PL_NA,DS_INPUT,ACT,FIN,FY16,CO_8304,CC_8180,AC_684100,0.00,0.00,0.00,0.00,100.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
CP_NA,PL_NA,DS_INPUT,ACT,FIN,FY16,CO_8304,CC_8180,AC_542900,0.00,0.00,0.00,0.00,3191.08,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
CP_NA,PL_NA,DS_INPUT,ACT,FIN,FY16,CO_8304,CC_8180,AC_683000,0.00,0.00,0.00,0.00,234.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
CP_NA,PL_NA,DS_INPUT,ACT,FIN,FY16,CO_8304,CC_8180,AC_606010,0.00,0.00,0.00,0.00,63694.27,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00


So, what's shown in red is actually 12 records, not 1. Is there anyway to calculation this for all search files and return a total?

The data file can have 13 colums more more. But, the last 12 are always data as I said, which should help derive the logic?

Thank you, Dave!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Return total number of found strings using JREPL

#8 Post by foxidrive » 11 Aug 2016 20:14

SIMMS7400 wrote:For instance, I'm running this script over 12 files equaling about 24gigs. It takes approx 1.5 hours.


Gee, I wonder if there is a post anywhere that describes how a task needs to be explained so that helpers have a good clue about what they are helping with?

viewtopic.php?f=3&t=6108

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Return total number of found strings using JREPL

#9 Post by SIMMS7400 » 12 Aug 2016 01:32

Fox -

I believe my last requirement is explained well enough in the post immediately above yours. let me know if you think otherwise.


Thanks!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Return total number of found strings using JREPL

#10 Post by foxidrive » 12 Aug 2016 07:33

SIMMS7400 wrote:I believe my last requirement is explained well enough in the post immediately above yours. let me know if you think otherwise.

How long have you been processing 24 gigabyte worth of files? Your 12 files?

Do you really think you have described your task well at any stage when you are processing these abnormally large files and have only just mentioned it?

Or did you mention it earlier, buried deep in a thread?

Post Reply