在Cygwin gawk给予"访问被拒绝"错误

时间:2017-03-22 17:07:04

标签: awk cygwin access-denied

我试图使用Cygwin运行一个简单的awk命令。

我想运行一个文件并将每行放到一个名为与第一个字段相同的文件中,将第一个字段中具有相同值的行追加到相关文件中。

我正在运行此命令:

gawk -F , '{print>\$1}' ./filename.csv

我从命令获得的唯一输出是:"访问被拒绝。"

C:\projects>gawk -F , '{print>\$1}' ./filename.csv  
Access is denied.

这就是它的总体情况。

我查看了文件权限并允许了所有内容,但我似乎无法让它工作。

根据要求编辑额外信息:

C:\projects>gawk -F , '{print > \$1}' filename.csv
Access is denied.

C:\projects>$SHELL --version
'$SHELL' is not recognized as an internal or external command,
operable program or batch file.

C:\projects>gawk --version
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.2)
Copyright (C) 1989, 1991-2016 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

我试过从Cygwin Shell运行,我现在收到此错误:

/cygdrive/c/projects/FileSplit
$ gawk -F , '{print > $1}' ./filename.csv
gawk: cmd. line:1: (FILENAME=./filename.csv FNR=1) fatal: expression for `>' redirection has null string value

在Cygwin Shell中运行它虽然我的第一个字段在某些行上是空白的,但我最终得到的命令是:

gawk -F , '{if(length($1)==0)print > "empty"; else print > $1}' ./filename.csv

1 个答案:

答案 0 :(得分:0)

摆脱反斜杠:

gawk -F , '{print > $1}' ./filename.csv

鉴于您现在已经添加到您的问题中 - 您正在从Windows CMD提示中运行gawk,而不是从cygwin运行。不要这样做,从cygwin终端窗口运行gawk,而不是执行All Programs -> Cygwin -> Cygwin64 Terminal之类的操作来启动运行bash shell的cygwin窗口。

相关问题