简体   繁体   中英

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

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 , eg 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM