【问题标题】:find /C "A" results in "find: 'A': No such file or directory"find /C "A" 结果为“find: 'A': No such file or directory”
【发布时间】:2017-07-10 15:15:18
【问题描述】:

我正在尝试计算 the answer here 之后的文件中的行数,例如使用find /C,但我在控制台中看到的只是:

find: '/C': No such file or directory
find: 'A': No such file or directory

我有一个简单的“TEST.txt”文件,其中包含三个 As 和三个 B,都在新行中:

$ type TEST.txt
A
A
A
B
B
B

findstr 似乎可以工作,但它不能返回计数:

$ type TEST.txt | findstr "A" 
A                             
A                             
A   

查找不起作用:

$ type TEST.txt | find "A"
find: 'A': No such file or directory

我错过了什么?

PS:来自1 的整个示例也无法正常工作:

$ findstr /R /N "^" TEST.txt | find /C ":"
find: '/C': No such file or directory
find: ':': No such file or directory

编辑:

因为了解正在发生的事情可能很重要:我使用的是ConEmu terminal

【问题讨论】:

  • 您是从cmd.exe 还是powershell.exe 调用find
  • TEST.txt 是现有文件吗?你的确切命令findstr /R /N "^" TEST.txt | find /C ":" 对我有用,在我计算“A”出现次数的文件上。
  • 顺便说一句,我用过cmd.exe。他的错误看起来像是 UNIX 会返回的。 powershell.exe 将返回 FIND:Parameter format not correct,因为语法不同。
  • 据我了解,我使用的是cmd.exe(FreeCommander XE 中的命令/cmd {Shells::cmd (Admin)})...
  • 而 TEST.txt 是一个现有文件...findstr /R /N "^" TEST.txt | find /C ":" 仍然为我返回 find: '/C': No such file or directoryfind: ':': No such file or directory

标签: windows cmd findstr


【解决方案1】:

在包含 find.exe 的 Windows 目录之前的 PATH 中是否有包含 find.exe 的 ConEmu 二进制目录?

如果您无法更改 PATH 变量,您可以使用 %windir%\System32\find.exe 指定 Windows 查找的完整路径。

【讨论】:

  • RTools 对我做了这个,没想到另一个 find.exe 会跳到 PATH 变量中的 %windir%\system32 前面。
【解决方案2】:

您在 UNIX shell 上使用 Windows 的 cmd.exe 命令。 UNIX 上的 find 与 Windows shell 上的 find 不同。

要在 linux 中计算文件中的行数,请使用 wc -l /path/to/file

如果您想使用 Windows CLI,请打开 cmd.exe 并使用您链接到的答案:

findstr /R /N "^" <FILENAME> | find /C ":"

如果您想更进一步并添加更多选项,请查看this link

【讨论】:

  • 我现在更困惑了...我正在使用 Windows 开始菜单打开cmd.execmd.exe 在 ConEmu 中打开,我认为这只是一个允许复制的“方便的 Windows 终端” ,粘贴等,findstr /R /N "^" TEST.txt | find /C ":" 不起作用,但 wc -l TEST.txt 可以...
  • 在包含 find.exe 的 Windows 目录之前的 PATH 中是否有包含 find.exe 的 ConEmu 二进制目录?我承认我不知道 ConEmu,但只是猜测。
  • 猜对了@lit!这不是 ConEmu 本身,而是 Rtools 有 find.exe,带有 Windows 的完整路径 findstr /R /N "^" TEST.txt | C:\Windows\System32\find.exe /C ":" 就像一个魅力。 where find 在这里完成了这项工作。请将此作为答案发布,我会接受。
  • Rizky Fakkel,+1 为您添加了一些背景知识!我接受@lit 答案作为解决方案,因为它直接解决了它,但您的输入在这里也很有价值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 2020-01-31
  • 2023-02-06
  • 2012-10-05
  • 2016-01-05
  • 2016-11-01
相关资源
最近更新 更多