Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to running Gnuwin32 gawk in Windows

1,546 views
Skip to first unread message

moonhkt

unread,
Apr 2, 2011, 5:17:03 AM4/2/11
to
Hi All

How to running Gnuwin32 gawk in Windows ?

I created a file hello.bat as below, it print itself

gawk '{
print $0
}' hello.bat

run at DOS prompt as below

D:\Example\Software\gawk>hello.bat

D:\Example\Software\gawk>gawk '{
gawk: cmd. line:1: {
gawk: cmd. line:1: ^ unexpected newline or end of string

D:\Example\Software\gawk>print $0
Can't find file $0

D:\Example\Software\gawk>}' hello.bat
'}'' is not recognized as an internal or external command,
operable program or batch file.

D:\Example\Software\gawk>

Manuel Collado

unread,
Apr 2, 2011, 6:16:53 AM4/2/11
to
El 02/04/2011 11:17, moonhkt escribió:
> Hi All
>
> How to running Gnuwin32 gawk in Windows ?
>
> I created a file hello.bat as below, it print itself
>
> gawk '{
> print $0
> }' hello.bat
>

Should be:

gawk "{print $0}" hello.bat

> run at DOS prompt as below
>
> D:\Example\Software\gawk>hello.bat
>
> D:\Example\Software\gawk>gawk '{
> gawk: cmd. line:1: {
> gawk: cmd. line:1: ^ unexpected newline or end of string
>
> D:\Example\Software\gawk>print $0
> Can't find file $0
>
> D:\Example\Software\gawk>}' hello.bat
> '}'' is not recognized as an internal or external command,
> operable program or batch file.
>
> D:\Example\Software\gawk>

In MS-DOS/Windows the newline acts as command terminator. You can't spread
a string literal or a single command over several lines.

In all cases, it is better to put the AWK code in a file by itself (say
hello.awk) and invoke it as

gawk -f hello.awk ... files...

This practice avoids a lot of quoting problems.

Regards,
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado

Janis Papanagnou

unread,
Apr 2, 2011, 6:32:43 AM4/2/11
to
On 02.04.2011 11:17, moonhkt wrote:
> Hi All
>
> How to running Gnuwin32 gawk in Windows ?

Put your awk program

{
print $0
}

in a file xyz.awk and call it from your command prompt
or from a .bat file

awk -f xyz.awk


Janis

mss

unread,
Apr 2, 2011, 8:45:06 AM4/2/11
to
Janis Papanagnou wrote:

> On 02.04.2011 11:17, moonhkt wrote:
>> Hi All
>>
>> How to running Gnuwin32 gawk in Windows ?
>
> Put your awk program
>
> {
> print $0
> }
>
> in a file xyz.awk and call it from your command prompt
> or from a .bat file
>
> awk -f xyz.awk
>
>
> Janis

And an expanded example for the OP to consider as well:

:: note always use forward slashes when specifying a path

:: path to [m|g]awk interpreter
set AWK="gawk.exe"

:: path to awk script
set SCR="tool.awk"

:: path to data
set DTA="input.txt"

if not exist %AWK% (
echo cannot continue %AWK% not found...
goto :eof
)

if not exist %SCR% (
echo cannot continue %SCR% not found...
goto :eof
)

if not exist %DTA% (
echo cannot continue %DTA% not found...
goto :eof
)

%AWK% -f %SCR% < %DTA% 2>> error.log

:: also an example of passing arguments to an
:: awk script when invoked as 'tool.bat xyz'
:: %AWK% -v VAR=%* -f %SCR% < %DTA% 2>> error.log

:eof


--
later on,
Mike

http://www.topcat.hypermart.net/index.html

0 new messages