-1

I have a folder which has multiple type of files (word/excel/pdf/notepad). i want to list the which has the string inside the file.

eg:

  1. vijay - list the files only if it has a string anywhere inside the file as "vijay"

  2. vijay kumar - list only the file which has "vijay kumar" inside the file

I tried below command but its either not listing the files or pulling files which doesn't have vijay inside.

findstr /s /i /m /c:"vijay" *.*  > vijay.txt;

can you please provide a windows script, where i can get the list of files based on my search term

0

2 Answers 2

0
  1. Install the latest version of WSL.
  2. Use grep -- grep -a [-r] -l '<regular_expression>'

The -r flag will cause it to recurse subdirectories. If you want it to also follow shortcuts, use -R instead of -r.

If you want the line(s) containing the matching string, omit the -l. If you want line numbers in front of the matching lines, use -n.

The grep command has many many more options.

I won't completely explain "regular expression" here, but suffice it to say that "Vijay" will match any string containing Vijay and "Vijay Kumar" will match any string containing Vijay Kumar. However, there are also other things you can do, for example, '([\da-fA-F]{1,2}[:.-]){5}[\da-fA-F]{1,2}' will match a MAC address using :, -, or . to separate the octets and represented in hex. (It won't match the weird Cisco aaaa.aaaa.aaaa format or the even weirder Cisco aaaa-aaaa-aaaa format, but it will match the standard 12:34:56:78:9a:bc format with any combination of :, -, or . as the separator.

() is a grouping of regular expression components. [] builds a character class, so any of the specified characters in the class will match. The class [\da-fA-F] will match any digit (\d = a character class of digits 0-9), any letter in the range a-f or any capital letter in the range A-F. So basically, this character class will match a single hex digit. The {x,y} construct is a range. It means match x-y instances of the preceding regular expression. So the {1,2} after the character class will match 1 or 2 hex digits. Next we define a character class for the separators. Since . and - are normally special in regular expression character classes (. means match any single character, - is used to specify a range (e.g. a-f = a,b,c,d,e, or f), in order to match them literally, they must be escaped with a \ character. So now we have an expression that matches 1-2 hex digits followed by a :, -, or . -- This is what we put in parenthesis so that we can then {5} match it 5 times. Then we repeat the 1-2 hex digits specification without a trailing delimiter to match the 6th octet.

As you can see, this allows you to do a LOT of really cool things fairly easily.

These tools are built into reputable operating systems, but you need to add Windows Subsystem for Linux to be able to use them on Windows (which seems to be what you are most likely using).

Sign up to request clarification or add additional context in comments.

1 Comment

Meh... YMMV, but I find a good command line tool to usually be far more efficient than navigating a GUI, especially for something like a simple recursive text search. WSL is also "native" in that it is a package Microsoft provides for Windows that can be easily installed and comes with a large number of useful CLI tools. YMMV.
0

There are reasons why Findstr cannot see a string such as "vijay"

    1. It may ignore some of those that have adjoining symbols but then again it may not. enter image description here
    1. it cannot decompress zip nor docx nor decode a PDF, however explorer search can if set to include iFilters.

If you set up Windows search correctly you may get in just a few seconds a result from the constantly updated index, so in my downloads area I find your name 25 times. Apparently among 100s of thousands of files!

Whilst it's not part of your question, there are many alternative methods and perhaps the best for your type of task is to look at MythicSoft AgentRansack Pro https://help.mythicsoft.com/filelocatorpro/v9/en/index.html?index-interface.htm or perhaps Swiss File Knife/Depeche however that may not work with PDF indexing.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.