to use the search criteria in Criteria.txt to search the files listed in Files.txt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

to use the search criteria in Criteria.txt to search the files listed in Files.txt

#1 Post by goodywp » 12 Oct 2017 15:50

I have a two text files
1) string.txt
500007011000.S3S
500008011000.S3S
500022010300.S3S

2) list.txt

“C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500006011000.S3S”
“C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500007011000.S3S”
“C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500008011000.S3S”
“C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500009011000.S3S”
“C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500022010300.S3S”

What I am looking for is this output, a file (newlist.txt) like this:

“C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500007011000.S3S”
“C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500008011000.S3S”
“C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500022010300.S3S”

I tried this as below looks not working...

Code: Select all

FINDSTR /g:string.txt /f:list.txt >>newlist.txt
Last edited by goodywp on 12 Oct 2017 18:29, edited 1 time in total.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#2 Post by penpen » 12 Oct 2017 17:40

You don't want to search within the files listed in txt, therefore the option /F is wrong.
This should be what you are searching for:

Code: Select all

FINDSTR /G:"string.txt" "list.txt"

Sidenote: Please use [code][/code] tags.

penpen

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#3 Post by goodywp » 12 Oct 2017 18:45

tried and did not get anything...

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#4 Post by penpen » 13 Oct 2017 03:21

Tested the above command successfully under WinXP and Win 10.
I haven't redirected the result to "newlist.txt", so the result is only shown on screen:

Code: Select all

Z:\>FINDSTR /G:"string.txt" "list.txt"
"C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500007011000.S3S"
"C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500008011000.S3S"
"C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500022010300.S3S"

Z:\>

With the above redirection the command is:

Code: Select all

>>"newlist.txt" FINDSTR /G:"string.txt" "list.txt"
Test:

Code: Select all

Z:\>>>"newlist.txt" FINDSTR /G:"string.txt" "list.txt"

Z:\>type "newlist.txt"
"C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500007011000.S3S"
"C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500008011000.S3S"
"C:\TEST\T501-08680-0102\Application_Signing\Signed_Schemes\MockupSigned_T3\500022010300.S3S"

Z:\>

There are some whitespaces in your data, but i'm unsure wether these characters are there because of not using code tags around your source file contents (== added accidentally by your browser), or if these characters are really there:
You have to remove these unwanted whitespaces if they are present; i used this "string.txt":

Code: Select all

500007011000.S3S
500008011000.S3S
500022010300.S3S

If that doesn't work, then you have to check if the files are stored in the same coding (ANSI/Unicode/...).

penpen

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#5 Post by goodywp » 13 Oct 2017 06:39

Thanks so much!!! I checked it again as you pointed out. The source files for both string.txt and list.txt. There is one space at the end of each line. These was due to the previous step generated these files. So that means I have to add one more step to process the files before it can be used... :)

One more question for you. Is it quite normal like this? I means that a lot of times the batch generated txt file having a space at the end or we can prevent it happen in the coding....

Code: Select all

setlocal enabledelayedexpansion

for /f "delims=" %%i in (schemeslist%VAR14%.txt) do (

    set line=%%i C:\auto_pkg_build\Tools\PACKAGER\S3S\temp

    echo !line:~47, 16! >>%VAR14%.txt


Thanks again

William
Last edited by goodywp on 13 Oct 2017 08:57, edited 1 time in total.

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

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#6 Post by Squashman » 13 Oct 2017 07:22

goodywp wrote:
One more question for you. Is it quite normal like this? I means that a lot of times the batch generated txt file having a space at the end or we can prevent it happen in the coding....

Thanks again

William


If you had a batch file creating those text file lists, you most likely are echoing a space to the files. Without seeing the code you used to make those text files we can only assume what is happening.

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#7 Post by goodywp » 13 Oct 2017 08:59

I added the code to generate this txt file:

Code: Select all

setlocal enabledelayedexpansion

set VAR14=%VAR14: =%

for /f "delims=" %%i in (schemeslist%VAR14%.txt) do (

    set line=%%i C:\auto_pkg_build\Tools\PACKAGER\S3S\temp

    echo !line:~47, 16! >>%VAR14%.txt


Thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#8 Post by aGerman » 13 Oct 2017 09:11

Code: Select all

...16! >>...
Do you see your space :?: :lol:
Whenever possible write redirections in opposite order.

Code: Select all

>>"%VAR14%.txt" echo !line:~47,16!

Steffen

// EDIT:
Even the string manipulation seems to be strange. What's the reason for this ~47,16? To pick the file name out of a path?
Try

Code: Select all

>>"%VAR14%.txt" echo %%~nxi

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

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#9 Post by Squashman » 13 Oct 2017 11:12

goodywp wrote:I added the code to generate this txt file:

Code: Select all

setlocal enabledelayedexpansion

set VAR14=%VAR14: =%

for /f "delims=" %%i in (schemeslist%VAR14%.txt) do (

    set line=%%i C:\auto_pkg_build\Tools\PACKAGER\S3S\temp

    echo !line:~47, 16! >>%VAR14%.txt


Thanks

Given the two text file examples you gave us above, I fail to see how this code created that output.

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt

#10 Post by goodywp » 16 Oct 2017 11:36

Thank all for all the replies.

Squashman, the one I used is just want to simplified question. Since the real one is a dynamic txt file based upon the var14.

Steffen, thank you always for your constructive suggestion which make the code simple and beauty... :D

Post Reply