Page 1 of 1

Return total number of found strings using JREPL

Posted: 09 Aug 2016 07:54
by SIMMS7400
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!

Re: Return total number of found strings using JREPL

Posted: 09 Aug 2016 09:54
by foxidrive
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?

Re: Return total number of found strings using JREPL

Posted: 09 Aug 2016 19:19
by dbenham
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

Re: Return total number of found strings using JREPL

Posted: 10 Aug 2016 04:31
by SIMMS7400
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!

Re: Return total number of found strings using JREPL

Posted: 10 Aug 2016 04:42
by dbenham
Oops :oops:

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


Dave Benham

Re: Return total number of found strings using JREPL

Posted: 10 Aug 2016 06:56
by SIMMS7400
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!

Re: Return total number of found strings using JREPL

Posted: 10 Aug 2016 08:04
by SIMMS7400
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!

Re: Return total number of found strings using JREPL

Posted: 11 Aug 2016 20:14
by foxidrive
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

Re: Return total number of found strings using JREPL

Posted: 12 Aug 2016 01:32
by SIMMS7400
Fox -

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


Thanks!

Re: Return total number of found strings using JREPL

Posted: 12 Aug 2016 07:33
by foxidrive
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?