如何正确管道命令在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:无法打开文件'|'进行读取(无此文件或目录)
我读某处在Windows机器上可以使用';'代替'|',虽然这会导致类似的错误。 p>
似乎它正在读取'|'作为文件名的第一个实例,这是在Windows机器上的管道的正确方法吗?机器使用Cygwin?
编辑:我添加cygwin到windows的PATH变量,然后使用cmd窗口如果我想真正使用cygwin.exe,这意味着我会有要在C:/ cygwin中放置我想要编辑的任何文件?
!从cygwin执行cygwin命令,而不是从Windows。要对任何文件执行cygwin命令,只需给命令文件的完整路径(但以 / cygdrive /
开头),它不必在 C:/ cygwin
,例如从cygwin shell窗口查看常见的Windows文件夹中的内容 C:\Documents和设置
:
$ ls -Q'/ cygdrive / c /文档和设置'
所有用户默认默认用户desktop.iniemorton b $ b
I'm trying to run experiments on a text file to get word frequencies. I tried using the following command:
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
But I get the following error:
gawk: cmd. line:1: fatal: cannot open file '|' for reading (No such file or directory)
I read somewhere that ';' may be used instead of '|' on Windows machines, although this results in a similar error.
It seems as though it is reading the first instance of '|' as a file name. Is this the correct way of piping on a windows machine? Is piping possible on a windows machine using Cygwin?
EDIT: I added cygwin to windows PATH variable and then used cmd window. If i wanted to actually use cygwin.exe, does that mean I would have to place any files I wanted to edit within C:/cygwin ?
OK, now I understand - don't do that! Execute cygwin commands from cygwin, not from Windows. To execute a cygwin command on any file, just give the command the full path to the file (but starting with /cygdrive/
), it doesn't have to be under C:/cygwin
, e.g. from a cygwin shell window to see what's in the common Windows folder C:\Documents and Settings
:
$ ls -Q '/cygdrive/c/Documents and Settings'
"All Users" "Default" "Default User" "desktop.ini" "emorton" etc...
这篇关于如何正确管道命令在Cygwin(使用Windows)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!