Page 1 of 1
search for list of filenames in a single file
Posted: 22 Mar 2012 06:10
by ladduq
Hi
Need help to search for list of filenames in a single file.
Lets say the file information.txt contains lakhs of filenames but i only need to get a list of hundred filenames with all the instances in that file.
lets say information.txt contains
1 1.txt
2 2.txt
3 3.txt
4 2.txt
5 4.txt
6 5.txt
7 2.txt
8 6.txt
9 2.txt
10 1.txt
if the search criteris is "1.txt" and "2.txt"
the output should be
start
=================
1 1.txt
2 2.txt
4 2.txt
7 2.txt
9 2.txt
10 1.txt
=====================
end
the same should be applicable for any no of files with any no of instances as in this case we have only 2 files as our search criteria.
Regards
Ladduq
Re: search for list of filenames in a single file
Posted: 22 Mar 2012 06:13
by tonysathre
C:\temp>findstr "1.txt 2.txt" information.txt
1 1.txt
2 2.txt
4 2.txt
7 2.txt
9 2.txt
10 1.txt
C:\temp>
Re: search for list of filenames in a single file
Posted: 22 Mar 2012 15:24
by dbenham
@tonysathre
That search will be treated as a regex, and the dot will match any character. Not what is wanted.
You need to add the /L (literal) option to the findstr command.
Also, you can't search for file names that contain spaces that way. For spaces you need the /c:"search" option.
Dave Benham
Re: search for list of filenames in a single file
Posted: 23 Mar 2012 10:33
by tonysathre
I thought that regex was only used when you specify /R. Is that not the case?
Tony
Re: search for list of filenames in a single file
Posted: 23 Mar 2012 10:35
by foxidrive
No, it defaults to regex
Good one Microsoft. Nice of them to include a /R switch.

Re: search for list of filenames in a single file
Posted: 23 Mar 2012 11:47
by miskox
tonysathre wrote:C:\temp>findstr "1.txt 2.txt" information.txt
1 1.txt
2 2.txt
4 2.txt
7 2.txt
9 2.txt
10 1.txt
C:\temp>
You should search for " 1.txt" so 11.txt or 101.txt are excluded. (of course with /C as others already mentioned).
Saso
Re: search for list of filenames in a single file
Posted: 23 Mar 2012 13:14
by !k
it defaults to regex
Hmm...

Re: search for list of filenames in a single file
Posted: 23 Mar 2012 23:12
by foxidrive
That's normal. What are you trying to say?
Re: search for list of filenames in a single file
Posted: 24 Mar 2012 01:05
by !k
it's no regexps
Re: search for list of filenames in a single file
Posted: 24 Mar 2012 02:34
by foxidrive
Code: Select all
@echo off
type nul> "Crystal Reports Shifts01.pdf"
type nul> "Crystal Reports Shifts02.pdf"
type nul> "Crystal Reports Shifts03.pdf"
type nul> "Crystal Reports Shifts04.pdf"
dir /b |findstr ..pdf
del "Crystal Reports Shifts0?.pdf"
pause
Re: search for list of filenames in a single file
Posted: 24 Mar 2012 02:45
by foxidrive
With the literal string /c: switch it switches to literal mode.