1

In MS Windows XP, in DOS, is it possible to do a content search(for a line or a word) in a file using command prompt.?

If so can we search a directory as well.? i.e it should search all the files in the directory for a specific word or phrase.

Thanks.

1
  • 2
    What platform and shell? Jun 17, 2010 at 5:20

4 Answers 4

3

There are two options: FIND or FINDSTR, both of which are built-in to the Windows Command Prompt.

You can use FIND to search for a simple string in a file:

FIND "apple" file.txt

You can also use it to search all files in the current directory:

FIND "apple" *

FINDSTR has a few more options: you can do searches with regular expressions, and you can search recursively into subdirectories:

FINDSTR /s "apple" *

In all cases, these commands print each line that matches the string to be searched, along with the file they were found in.

0

if you are looking for out of the box solution then you can use the fndstr command which comes with XP.

0

FINDSTR

0

On unix the command is find, which takes a mini-language on the command line for defining what to find.

The short version of how to use it is:

$ find [where in the file tree to start]+ [how to filter files]+ [actions]+

and a common usage would be

$ find . ~ -name '*.mp3' -print

which means start in this directory (.) and my home directory (~), select only files with names ending in .mp3 (the -name filter), and print the path (using the -print action).

There are many more selection operators, and a modest set of actions. To do something complicated with the files you've found you either use -exec or print their names and pipe to xargs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .