简体   繁体   中英

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. If I paste it into the DOS command line window (I'm using Win 7) it executes fine.

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. 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:

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. 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. If the first file it lists has the filename gawk.bat or gawk.cmd then either delete that file or rename it.

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