Page 1 of 1
to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 12 Oct 2017 15:50
by goodywp
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
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 12 Oct 2017 17:40
by penpen
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
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 12 Oct 2017 18:45
by goodywp
tried and did not get anything...
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 13 Oct 2017 03:21
by penpen
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
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 13 Oct 2017 06:39
by goodywp
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
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 13 Oct 2017 07:22
by Squashman
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.
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 13 Oct 2017 08:59
by goodywp
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
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 13 Oct 2017 09:11
by aGerman
Do you see your space
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
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 13 Oct 2017 11:12
by Squashman
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.
Re: to use the search criteria in Criteria.txt to search the files listed in Files.txt
Posted: 16 Oct 2017 11:36
by goodywp
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...
