简体   繁体   English

Gawk命令未从批处理文件执行,但在命令行上正常

[英]Gawk command not executing from batch file but fine at command line

Have a problem here but I don't know what type of problem it is, so it's proving difficult to find out a solution. 这里有问题,但我不知道这是什么类型的问题,因此事实证明很难找到解决方案。 Could be a flushing/buffer thing, or a batch file vs command line syntax issue, not sure. 不确定可能是刷新/缓冲事件,还是批处理文件与命令行语法问题。

I have a batch file that has a gawk command in it, but it's not executing properly. 我有一个包含gawk命令的批处理文件,但是执行不正确。 If I paste it into the DOS command line window (I'm using Win 7) it executes fine. 如果我将其粘贴到DOS命令行窗口中(我使用的是Win 7),它将正常执行。

The command is: 该命令是:

gawk 'BEGIN {FS=OFS="^"} {print $1,$3,$2}' /cygdrive/c/0temp2/input.txt > C:\0temp2\output.txt

(So I am simply trying to rearrange a few fields, with "^" as the field delimiter) (因此,我只是尝试重新排列一些字段,使用“ ^”作为字段分隔符)

If run from batch file, it looks like it is executing at the DOS prompt when the DOS command window pops up, but in fact it hangs, and meanwhile a separate file (let's call it banana.txt) pops up next to the .bat file that the script is running from, in the same directory, and the byte value (of banana.txt) keeps changing from 1 byte to zero bytes, indicating that it is being written to by the script. 如果从批处理文件运行,则似乎在DOS命令窗口弹出时正在DOS提示符下执行,但实际上它挂起了,与此同时,.bat旁又弹出了一个单独的文件(我们称其为banana.txt)。脚本运行所在的文件(位于同一目录中),并且(banana.txt的)字节值一直从1字节更改为零字节,表明该脚本正在将其写入。 If I open banana.txt while it is being written to, assuming I catch it when it is not a zero byte file, it contains the following within it: 如果在写入banana.txt时打开它,并假设它不是零字节文件,则捕获了它,其中包含以下内容:

C:\0Temp>gawk 'BEGIN { FS = "^"; OFS = "^" } ; {gsub("1","s1",$10)}1' /cygdrive/c/0temp1/banana.txt 1>C:\0temp2\banana.txt 

This banana.txt file is familiar to me, and was operated on by a gawk command some days, even weeks, ago, but seems to have established its legacy and I can't get rid of the blasted thing. 这个banana.txt文件对我来说是很熟悉的,它是由gawk命令在几天甚至几周前进行操作的,但是似乎已经建立了它的遗产,我无法摆脱它。 Anyone know what is going on here ? 有人知道这是怎么回事吗? It's driving me crazy and all I find on the web are partial possible (and sometimes conflicting) solutions that point to the issue, but don't allow me to fix it because they're not specific enough and to be frank, I'm flying blind. 这让我发疯,并且我在网上发现的所有问题都可能是解决问题的部分解决方案(有时是相互冲突的),但由于其不够具体并且坦率地说,我不允许我对其进行修复,飞盲。

Type the command where gawk from the Windows command line prompt. 在Windows命令行提示符下键入命令where gawk If the first file it lists has the filename gawk.bat or gawk.cmd then either delete that file or rename it. 如果它列出的第一个文件的文件gawk.batgawk.cmd则删除该文件或重命名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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