如何在 Cygwin 中正确地传递命令(使用 Windows)?

How to correctly pipe commands in Cygwin (Using Windows)?

我正在尝试 运行 在文本文件上进行实验以获得词频。我尝试使用以下命令:

gawk -F"[ ,'\".]" -v RS="" '{for(i=1;i<=NF;i++) words[$i]++;}END{for (i in words) print words[i]" "i}' myfile.txt | uniq -c | sort -nr | head  -10

但是我收到以下错误:

gawk: cmd. line:1: fatal: cannot open file '|' for reading (No such file or directory)

我在某处读到 ';'可以用来代替'|'在 Windows 台机器上,尽管这会导致类似的错误。

它似乎正在读取“|”的第一个实例作为文件名。这是 windows 机器上管道的正确方法吗?使用 Cygwin 在 windows 机器上可以进行管道传输吗?

编辑:我将 cygwin 添加到 windows PATH 变量,然后使用 cmd window。如果我想实际使用 cygwin.exe,这是否意味着我必须将我想编辑的任何文件放在 C:/cygwin 中?

好的,现在我明白了 - 不要那样做!从 cygwin 执行 cygwin 命令,而不是从 Windows。要在任何文件上执行 cygwin 命令,只需为命令提供文件的完整路径(但以 /cygdrive/ 开头),它不必在 C:/cygwin 下,例如从 cygwin shell window 查看公共 Windows 文件夹中的内容 C:\Documents and Settings:

$ ls -Q '/cygdrive/c/Documents and Settings'
"All Users"  "Default"  "Default User"  "desktop.ini"  "emorton" etc...