Karl Major
Karl Major

Reputation: 137

FINDSTR in Command Prompt

I am trying to generate a file with all of the rows from an input file containing a certain string using the FINDSTR commanand in cmd.exe. My command below does not produce any results, whereas the FIND command (also below) shows that there are 182,688 rows containing the string I'm looking for...

FIND command:

FIND /c "searchstring" c:\Users\karl\Desktop\Report.csv

gives the following:

---------- C:\USERS\KARL\DESKTOP\REPORT.CSV: 182688

FINDSTR command:

findstr /i /c:"searchstring" c:\Users\karl\Desktop\Report.csv > results.out

gives me a blank file called results.out.

What am I missing?

Upvotes: 1

Views: 39538

Answers (3)

Zimba
Zimba

Reputation: 3701

Find some string inside all text files in current directory example:

cls & for %i in (*.txt) do find /i "search text" < "%i" && (echo : %i & echo -)

What you are missing is the redirector; if your last search file fails search, your code deletes all content of the result file. Replace with append redirector, eg, to store results of search in a file:

for %i in (*.txt) do (find /i "giff" < "%i" && (echo : %i & echo -)) >> results.txt

Tested in Win 10

Upvotes: 0

mmv_sat
mmv_sat

Reputation: 456

Try this one. the /n gives a line number:

findstr /i /n "\<searchstring\>" c:\Users\karl\Desktop\Report.csv

Upvotes: 0

dbenham
dbenham

Reputation: 130919

FINDSTR has many undocumented "features" that could be tripping you up. See What are the undocumented features and limitations of the Windows FINDSTR command?

You have not told us what your search string is, so I can't be sure. But your problem is probably related to one or more of the following:

  • Special rules for escaping " and \ within literal search strings
  • Many extended ASCII characters do not find themselves when used in command line search strings.
  • FINDSTR cannot search unicode files. I am told that FIND can search unicode files.

Upvotes: 3

Related Questions