Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Having problems to implement a dictonary counter

0 views
Skip to first unread message

Dennis Halver

unread,
Jun 19, 2009, 5:05:16 PM6/19/09
to
I am trying to write (under WinXP) a simple batch script for counting some special
terms in a file (lets call it dictionary). Below you will find a simplified version of it.

I have a dictionary text file where the first token in each line represents the number of occurencies.
The remaining 3 tokens represent the term. Sample:

10 a...@aaa.com (AAA BBB)
2 b...@bbb.com (CCC DDD)
30 c...@ccc.com (EEE FFF)
1 foo.bar (GGG HHH)
5 bbbbbb.coz (III JJJ)
1 bbbbbb.cozu (KKK LLL)

Now I want to find from a batch if a new term exists in the dictionary.
If yes the counter should be increased by 1 otherwise a new line should be inserted
with the initial start counter 1.
The resulting new dictionary textfile should be written to dict2.txt (not replacing the original).
My counter script looks so far as the one at the bottom of this posting.
However there are some errors. The script seems to have problems with the brackets.
It creates two dict files: "dict2.txt" (just the original) and "dict.txt)" with a new entry line.
Why does the script not correctly recognize the existing entry line?
How would the correct script look like?

Thank you

cls
@echo off
:: Default value:
set ynl=foo.bar ^(GGG HHH^)
set /p ynl=Enter value in format "aaa.bbb (ccc ddd)"
Echo used ynl=%ynl%

del dict2.txt 2>nul
setlocal enabledelayedexpansion
for /f "tokens=1-4" %%i in (dict.txt) do (
if "%%j"=="%ynl%" (set /a ycl=%%i+1&set ynl=) else (set ycl=%%i)
echo\!ycl! %%j %%k %%l>>dict2.txt
)

if defined ynl (echo\1 %ynl%>>dict2.txt)
pause

Dennis

0 new messages