i need help with pipe for findstr

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Roe5685
Posts: 9
Joined: 17 May 2012 20:37

i need help with pipe for findstr

#1 Post by Roe5685 » 02 Mar 2014 15:08

FindStrDrive(4) = "dir h:\ /s | findstr /i /g:FindSpec.txt" 'this works nicely could have 10 tokens!
FindStrDrive(0) = "dir h:\ /s | findstr /i " " iso$ com$ exe$ " " " works nicely too. again could have 10 tokens.
FindStrDrive(0) = "dir h:\ /s | findstr /i " & "iso$" works fine but "iso$ com$" NOT work. this using basic not dos.
FindStrDrive(0) = "dir h:\ /s | findstr /i " & str2 works fine but only if str2 is a SINGLE token. ( all your ideas work one token )

FindStrDrive(0) = "dir h:\ /s | findstr /i ' type str2 ' " or something like that might be the answer. i tried a few ideas by trial and error but got nowhere. I would not have a clue!

the mission make a file with say 2 tokens like echo iso$ + space + com$ into str2. then use str2 instead of by hand putting "iso$ com$ ".

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

Re: i need help with pipe for findstr

#2 Post by foxidrive » 02 Mar 2014 17:02

That isn't quite batch script and please describe what you need to do.

iso$ and com$ are not clear.

Roe5685
Posts: 9
Joined: 17 May 2012 20:37

Re: i need help with pipe for findstr

#3 Post by Roe5685 » 02 Mar 2014 18:27

you say it not quite clear what i WANT TO DO.

you see that using a text file or by manual typing in you get findstr processing from the dir command say iso com and exe.
i.e. it will find all of files with these endings on your hard drive. the $ sign limits findstr to looking at the end of the file name.
we don't want files like say xxxxcomyyy.txt coming up on a com search. We only want xxxx.com and so forth.
the text file works and so does manual insertion. we are trying to get a string to work. now it only work for ONE token not the 2 or 3 listed.
Is this clear? the pipe command ( see Microsoft site on pipe ) directs DIR results to findstr to process.

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

Re: i need help with pipe for findstr

#4 Post by foxidrive » 02 Mar 2014 18:35

Try this command to see if it shows what you are after:

Code: Select all

dir h:\*.iso  h:\*.exe  h:\*.com /b /s /a-d

Roe5685
Posts: 9
Joined: 17 May 2012 20:37

Re: i need help with pipe for findstr

#5 Post by Roe5685 » 20 Mar 2014 20:47

your dir h:\*.iso h:\*.exe h:\*.com /b /s /a-d is I must say BRILLIANT.
when I looked at this code I said "That will never work!". but it works fine.
Thanks for that.
I guess we could make a batch file with iso etc as 1% 2% and so forth?

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

Re: i need help with pipe for findstr

#6 Post by Squashman » 20 Mar 2014 22:29

You can only reference %1 to %9. If you have more than 9 command line arguments then you would need to use shift to capture the remaining arguments.

Roe5685
Posts: 9
Joined: 17 May 2012 20:37

Re: i need help with pipe for findstr

#7 Post by Roe5685 » 21 Mar 2014 06:22

thanks for the more than 9 % commands points.
i tested the FOXIDRIVE method and it works fine with 4.
i was amazed how long you can make the DIR line!
dir c:\%1 c:\%2 c:\%3 c:\%4 d:\%1 d:\%2 d:\%3 d:\%4 f:\%1 f:\%2 f:\%3 f:\%4 g:\%1 g:\%2 g:\%3 g:\%4 h:\%1 h:\%2 h:\%3 h:\%4 /s /a-d >> yyy.doc
however the above was no faster than one line for each drive.
getting back to the original question. i have found the freebasic solution.( the solution came from ZIPPY ).
FindStrDrive(0) = "dir h:\ /s | findstr /i " " iso$ com$ exe$ " " " works nicely too. again could have 10 tokens.
but
FindStrDrive(0) = "dir h:\ /s | findstr /i " & str$ does not work for more than one token in Str$.
the answer is to use chr$(34) around str$. then multiple tokens work.
Shell "findstr /i " & qt & str33 & qt & " newharry.doc > Nfinishedharry.doc" 'works fine
HOWEVER the FOXIDRIVE method is superior.
My freebasic "do all the files" about 750K is about 11 seconds. With the above the DOS version is around 15 seconds.
Before that the DOS version was around 30 seconds.
THAT IS ONE COOL DIR COMMAND. THANKS AGAIN.

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

Re: i need help with pipe for findstr

#8 Post by foxidrive » 21 Mar 2014 06:33

:)

Post Reply