Problem duplicate findstr command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Problem duplicate findstr command

#1 Post by darioit » 13 Apr 2012 04:47

hello,

I have this issue using findstr command

searching filename: invoices.txt and invoices.dett.txt inside file tabella.txt

in tabella.txt there's this information
invoices.fatt.txt;dest1;dest2;dest3
invoices.txt;dest1;dest2;dest3


Code: Select all

FOR %%i in (%ORIGINE_DATI%\*.*) DO CALL :ELABORA %%~nxi 

:ELABORA
SET stringa=%1
FOR /F "tokens=1,2,3,4 delims=;" %%a IN ('FINDSTR %stringa:~,-8% %SCRIPTS%\Tabella.txt') DO (
   IF NOT EXIST "%DEST_DATI%-%AA_DATE%\%%c\%%b" mkdir "%DEST_DATI%-%AA_DATE%\%%c\%%b"
   IF "%%c" EQU "Dest2" MOVE /Y "%ORIGINE_DATI%\%1" "%DEST_DATI%-%AA_DATE%\%%c\%%b\%AA_DATE%-%MM_DATE% %1.%%d"
   IF "%%c" EQU "Dest3" MOVE /Y "%ORIGINE_DATI%\%1" "%DEST_DATI%-%AA_DATE%\%%c\%%b\%AA_DATE% %1.%%d"
   GOTO:EOF
)


name "invoices" is common, so this batch run twice, how can I solve this problem?

Regards

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

Re: Problem duplicate findstr command

#2 Post by foxidrive » 13 Apr 2012 07:13

I didn't study your code in detail - there is an error that will cause :ELABORA routine to run again, because the first line should be followed by goto :EOF

See below.

Code: Select all

FOR %%i in (%ORIGINE_DATI%\*.*) DO CALL :ELABORA %%~nxi 

goto :EOF

:ELABORA
SET stringa=%1
FOR /F "tokens=1,2,3,4 delims=;" %%a IN ('FINDSTR %stringa:~,-8% %SCRIPTS%\Tabella.txt') DO (
   IF NOT EXIST "%DEST_DATI%-%AA_DATE%\%%c\%%b" mkdir "%DEST_DATI%-%AA_DATE%\%%c\%%b"
   IF "%%c" EQU "Dest2" MOVE /Y "%ORIGINE_DATI%\%1" "%DEST_DATI%-%AA_DATE%\%%c\%%b\%AA_DATE%-%MM_DATE% %1.%%d"
   IF "%%c" EQU "Dest3" MOVE /Y "%ORIGINE_DATI%\%1" "%DEST_DATI%-%AA_DATE%\%%c\%%b\%AA_DATE% %1.%%d"
   GOTO:EOF
)

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: Problem duplicate findstr command

#3 Post by darioit » 13 Apr 2012 08:08

yes yes is correct, the original script is more complex

so my purpose is:

scan a directory, a lot filename are called:
aaa.bbb.ccc.ddd.G0001V00
aaa.bbb.ccc.ddd.dett.G0002V00
........

an array txt file that contain
aaa.bbb.ccc.ddd.eee;directory destinatio;name server;period;txt

my goal is read file and move to other destination with name:
"AAAAMM aaa.bbb.ccc.ggg.hhh.TXT"

but if a root name "aaa.bbb.ccc.ddd" is common, this script run twice, because find 2 times a name

Squashman
Expert
Posts: 4472
Joined: 23 Dec 2011 13:59

Re: Problem duplicate findstr command

#4 Post by Squashman » 13 Apr 2012 08:09

Are you saying you don't want to process any of the DETT files?

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

Re: Problem duplicate findstr command

#5 Post by foxidrive » 13 Apr 2012 08:34

I don't think there is enough info to tell what the problem is.

Can you shows us a real filename, and where it matches in two entries in the database?

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: Problem duplicate findstr command

#6 Post by darioit » 14 Apr 2012 00:06

ok this is the problem real simply

put in C:\Tabella.txt
aaa.bbb.ccc.ddd.dett;month;server2;csv
aaa.bbb.ccc.ddd;years;server1;txt


run command:
FINDSTR aaa.bbb.ccc.ddd C:\Tabella.txt

and the result is two raw, because "aaa.bbb.ccc.ddd" is in common
aaa.bbb.ccc.ddd.dett;month;server2;csv
aaa.bbb.ccc.ddd;years;server1;txt


I try to use FINDSTR "aaa.bbb.ccc.ddd" C:\Tabella.txt but same results

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

Re: Problem duplicate findstr command

#7 Post by foxidrive » 14 Apr 2012 04:20

I understand what you are saying, but to think of any solution then we need to see what is being parsed.
IE A solution could be in the makeup of the filename.


Or just use:

FINDSTR aaa.bbb.ccc.ddd C:\Tabella.txt|find /v ".dett"

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

Re: Problem duplicate findstr command

#8 Post by dbenham » 14 Apr 2012 12:32

Is the solution not as simple as including the delimiter in the search string?

Code: Select all

FINDSTR /L aaa.bbb.ccc.ddd; C:\Tabella.txt
The above should only find

Code: Select all

aaa.bbb.ccc.ddd;years;server1;txt

Even better would be to add the /B option to force the string to only match the beginning of the line.

Note - your original FINDSTR was doing a regular expression search because the search string contained an unescaped meta-character. The dot would match any character, so "aaaXbbbYcccZddd" would match. The solution is to either add the /L (literal) option, or else use the /C option because it always defaults to literal - /c:"aaa.bbb.ccc.ddd"


Dave Benham

Post Reply