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