Calling gawk from DOS batch script?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

Calling gawk from DOS batch script?

#1 Post by pstein » 20 Jan 2015 10:07

Assume I want to call gawk from DOS batch script.
I mean to gawk for windows available from here:
http://gnuwin32.sourceforge.net/packages/gawk.htm

I found samples like

@echo off & setlocal enableextensions
gawk 'BEGIN{printf"%%s\n",4/7}'
endlocal & goto :EOF

....but they don't work. I get an error:

gawk: 'BEGIN{printf%s\n,4/7}'
gawk: ^ invalid char ''' in expression

What do I have to change?

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Calling gawk from DOS batch script?

#2 Post by ShadowThief » 20 Jan 2015 10:12

Either have a line in your batch like

Code: Select all

set path=%path%;"C:\path\to\gawk.exe"


or

Code: Select all

start "" /b gawk 'BEGIN{printf"%%s\n",4/7}'

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Calling gawk from DOS batch script?

#3 Post by ShadowThief » 20 Jan 2015 10:16

Also, in Windows, you need double quotes around your gawk command.

Try

Code: Select all

gawk "BEGIN{printf\""%%s\n\"",4/7}"

Post Reply