FINDSTR in Command Prompt

2019-09-14 22:26发布

问题:

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?

回答1:

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.


回答2:

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

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