Page 1 of 1

Question about FINDSTR

Posted: 19 Jan 2011 01:41
by darioit
Hello everybody,

content file.txt
AAA;123;datiABCdati;querty;z
BBB;456;datiAAAdati;querty;z

content test.bat

Code: Select all

FOR /F "tokens=1 delims=." %%a IN ("%~nx1") DO FOR /F "tokens=1,2,3,4,5 delims=;" %%b IN ('FINDSTR %%a file.txt') DO (
SET A=%%b
SET B=%%c
SET C=%%d
SET D=%%e
SET E=%%f
)


CALL test.bat AAA.BBB.CCC

result:
BBB 456 datiAAAdati querty z

I like to search AAA for the 1 data before semicolon
Why the 2 row and not the First?
I aspect this row
AAA;123;datiABCdati;querty;z
(tokens=1 delims=.)

Regards
Dario

Re: Question about FINDSTR

Posted: 19 Jan 2011 02:21
by amel27
darioit wrote:Why the 2 row and not the First?

Because "AAA" contains in each line, but remain last var assignment,
try this FindStr call for search from begin to ";" char:

Code: Select all

FINDSTR /B "%%a;" file.txt

Re: Question about FINDSTR

Posted: 19 Jan 2011 02:26
by darioit
Now is better many thanks, but if I like to search some in the 2 field?

Regards
Dario

Re: Question about FINDSTR

Posted: 19 Jan 2011 03:09
by amel27
darioit wrote:to search some in the 2 field?
by regular expression feature:

Code: Select all

FindStr /BRC:"[^;]*;%%a;" file.txt