Need to reset the count to zero in batch after each address

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ken
Posts: 34
Joined: 09 Dec 2009 13:47

Need to reset the count to zero in batch after each address

#1 Post by Ken » 09 Dec 2009 14:00

How do I reset the variable %%a back to zero after it adds, so when it reaches the next line and the find variable %%a it will give a correct count.

When it finds the first address I want it to execute two more finds to give me a total for Request -DCC and Clean Request -DCC for that location, then drop down to another address and do two more finds giving a new count for Request -DCC and Clean Request -DCC.

Code:

type "MultiProperties06-09.txt" | find " 8550 N CENTRAL ACRD " >> "Updated Properties.xls"
for /f "tokens=2 delims=:" %%a in ('find.exe /C "Request - DCC" "MultiProperties06-09.txt"') do (echo Location has%%a Request - DCC>>"Updated Properties.xls" )
for /f "tokens=2 delims=:" %%a in ('find.exe /C "Clean Request - DCC" "MultiProperties06-09.txt"') do (echo Location has%%a Clean Request - DCC>>"Updated Properties.xls" )
type "MultiProperties06-09.txt" | find " 9850 N CENTRAL ACRD " >> "Updated Properties.xls"
for /f "tokens=2 delims=:" %%a in ('find.exe /C "Request - DCC" "MultiProperties06-09.txt"') do (echo Location has%%a Request - DCC>>"Updated Properties.xls" )
for /f "tokens=2 delims=:" %%a in ('find.exe /C "Clean Request - DCC" "MultiProperties06-09.txt"') do (echo Location has%%a Clean Request - DCC>>"Updated Properties.xls" )

Thank you for your help
Ken
Last edited by Ken on 14 Dec 2009 21:24, edited 1 time in total.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 10 Dec 2009 12:42

%%a is never 0, and it doesn't need to be reset -- it's only defined inside the for loop and it's value is determined uniquely each time it loops through the for command. It's not some type of value that increments or does addition.

Ken
Posts: 34
Joined: 09 Dec 2009 13:47

#3 Post by Ken » 10 Dec 2009 16:34

Thank you for explaining. I guess I need to reset the value of "Request -DCC" and "Clean Request -DCC" to zero but I haven't figured out how. I want it to count then reset to zero before reading the next address and so forth then continue until the end of file.

Thanks Ken

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 11 Dec 2009 15:16

In the code you have above, there is nothing that's counting -- other than the FIND statement. I'm completely not understanding what isn't working.

Ken
Posts: 34
Joined: 09 Dec 2009 13:47

I want it to reset the count after each address

#5 Post by Ken » 14 Dec 2009 21:11

avery_larry,

I want it to reset the count after each address, right now it counts all the Request - DCC and Clean Request - DCC in the entire file.

Example of current output:
Request - DCC = 1205 (for every location)
Clean Request - DCC = 1487 (for every location)
If it is reset to zero after each location I will get a correct total.

Example if I have a location at 8550 N CENTRAL ACRD that have the following (2 Request - DCC) and (5 Clean Request - DCC)

I would like it to total the following: Request - DCC = 2
Clean Request = DCC = 5
Total count for Location = 7

Then when it reads the next address 9850 N CENTRAL ACRD that have the following (6 Request - DCC) and (5 Clean Request - DCC)

I would like it to total the following: Request - DCC = 6
Clean Request = DCC = 5
Total count for Location = 11

Thank you for looking at the code
Ken

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#6 Post by avery_larry » 16 Dec 2009 10:56

So you have 1 big file, and then individual portions of the file you want treated separately?

That's a lot of work. You have to go line by line through it, keeping track of what part of the file you're in, and establish multiple variables that increment when you find the string, and finally put it all together after you've gone through the entire file.

Ken
Posts: 34
Joined: 09 Dec 2009 13:47

#7 Post by Ken » 16 Dec 2009 11:51

avery_larry

Thats correct... I am just having a problem with the totals after each address... It totals the entire file insead of each address. Do you have any suggestions?

Thanks for your help

Ken

Ken
Posts: 34
Joined: 09 Dec 2009 13:47

#8 Post by Ken » 16 Dec 2009 15:07

avery_larry

Do you have a sample of code I might try to reset counts in a file?

Thanks for your help
Ken

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#9 Post by avery_larry » 18 Dec 2009 15:31

Well, let's start with getting a sample of your input file . . .

Ken
Posts: 34
Joined: 09 Dec 2009 13:47

#10 Post by Ken » 18 Dec 2009 19:55

avery_larry

Thank you for you help... This is the type of data I am looking at when running my batch file although there is many more addresses.

09-00161921 Request - DCC 8550 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract
09-00161944 Clean Request - DCC 9850 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract

Thanks
Ken

Ken
Posts: 34
Joined: 09 Dec 2009 13:47

#11 Post by Ken » 21 Dec 2009 14:03

avery_larry wrote:Well, let's start with getting a sample of your input file . . .


avery_larry


Do you have any suggestions, example or sample code that I might use to attain the results I am looking for. I posted a sample of data.

Any help would be great

Thank you

Ken

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#12 Post by avery_larry » 22 Dec 2009 08:06

If EVERY LINE has the address you're interested in, then you can use a double find command:

type "MultiProperties06-09.txt" | find " 8550 N CENTRAL ACRD " >> "Updated Properties.xls"
for /f "tokens=2 delims=:" %%a in ('find " 8550 N CENTRAL ACRD " "MultiProperties06-09.txt"| find /C "Request - DCC" ') do (echo Location has%%a Request - DCC>>"Updated Properties.xls" )


So the find /c command which actually does the counting will only have the results of the find "property" command.

Ken
Posts: 34
Joined: 09 Dec 2009 13:47

#13 Post by Ken » 23 Dec 2009 08:53

avery_larry

Thank you for the code but it is still not giving me what I need.

With your code and a second find added for "Clean Request - DCC"
This is what the output looks like.

09-00161921 Request - DCC 8550 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract
09-00161928 Request - DCC 8550 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract
09-00161960 Clean Request - DCC 8550 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract
09-00161965 Clean Request - DCC 8550 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract
09-00161972 Clean Request - DCC 8550 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract
09-00161986 Clean Request - DCC 8550 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract
09-00161994 Clean Request - DCC 8550 N CENTRAL ACRD 54-M-Mapsco Page-Zone 005000-Census Tract


I am trying to get it with the totals at the bottom after each address.

Location has Request - DCC = 2
Location has Clean Request = DCC = 5
Total count for Location = 7

Then when it reads the next address it will show a new count.

Code Used:
type "MultiProperties06-09.txt" | find " 8550 N CENTRAL ACRD " >> "Updated Properties.xls"
for /f "tokens=2 delims=:" %%a in ('find " 8550 N CENTRAL ACRD " "MultiProperties06-09.txt"| find /C "Request - DCC" ') do (echo Location has%%a Request - DCC>>"Updated Properties.xls" )
find /C "Clean Request - DCC" ') do (echo Location has%%a Request - DCC>>"Updated Properties.xls" )

Thank you for all your help
Ken

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#14 Post by avery_larry » 23 Dec 2009 12:09

It should be as simple as changing the address in both of the find statements and it should give you the correct count.

Post your entire code if you're continuing to have problems.

Post Reply