Question about FINDSTR

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Question about FINDSTR

#1 Post by darioit » 19 Jan 2011 01:41

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

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Question about FINDSTR

#2 Post by amel27 » 19 Jan 2011 02:21

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

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

Re: Question about FINDSTR

#3 Post by darioit » 19 Jan 2011 02:26

Now is better many thanks, but if I like to search some in the 2 field?

Regards
Dario

amel27
Expert
Posts: 177
Joined: 04 Jun 2010 20:05
Location: Russia

Re: Question about FINDSTR

#4 Post by amel27 » 19 Jan 2011 03:09

darioit wrote:to search some in the 2 field?
by regular expression feature:

Code: Select all

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

Post Reply