问题
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 ?
回答1:
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...
来源:https://stackoverflow.com/questions/35753818/how-to-correctly-pipe-commands-in-cygwin-using-windows