Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: How to usin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 2232 of 2236
Post > Topic >>

Re: How to using gawk in Windows

by Ted Davis <tdavis@[EMAIL PROTECTED] > May 10, 2008 at 12:24 PM

On Fri, 09 May 2008 20:01:36 -0700, moonhkt wrote:

> On May 10, 4:28 am, Ted Davis <tda...@[EMAIL PROTECTED]
> wrote:
>> On Fri, 09 May 2008 10:36:27 -0700, moonhkt wrote:
>> > Hi All
>>
>> > D:\Example\Software\awk>uname -a
>> > CYGWIN_NT-5.1 moon 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin
>>
>> You might prefer a pure Windows port:
>> <http://gnuwin32.sourceforge.net/packages/gawk.htm>
>>
>> There are a few differences from Unix usage, mostly the command line
>> syntax and the fact that Windows doesn't implement some functions.
>>
>> In Windows, the oneliner for your tag.awk would be
>>
>>   awk "BEGIN{print \"eric\"}"
>>
>> There is no /dev/null in Windows - it's just 'nul'.
>>
>> --
The subject says "Windows" - some of your syntax indicates Windows, but
the rest of it is either Unix or Cygwin.  They don't mix.
> 
> in tag.bat
> @[EMAIL PROTECTED]
 off
> gawk 'BEGIN{print "eric"}'

NO - Windows requires Windows quoting conventions, not Unix conventions.
I have already  given you the correct quoting.
> 
> In Dos Prompt, run tag.bat ok
> D:\Example\Software\awk>tag
> eric

Not in Windows under CMD.exe it doesn't.  Screen dump:

c:\myfiles>test
gawk: cmd. line:1: 'BEGIN{print
gawk: cmd. line:1: ^ invalid char ''' in expression

> 
> D:\Example\Software\awk>tag
> eric
> 
> Do you know how to run tag.awk in prompt ?
> 
> D:\Example\Software\awk>cat tag.awk
> #!/usr/bin/gawk
> gawk 'BEGIN{print "eric"}'
> D:\Example\Software\awk>

That is mixed Unix and Windows syntax - it does't work. CMD.EXE does not
recognize shebang lines, and /usr/bin/gawk is meaningless to CMD - bash
understands shebangs, and Cygwin and *ix systems provide that file system
structure and syntax.

It is clear that you have some of the Gnu utilities, possibly in the form
of a Cygwin package.  If you launch Cygwin the way you are supposed to,
you have a bash shell, and Linux syntax and shell scripts mostly work - if
you try to use the tools directly, you *must* use Windows conventions.
This screen dump is a typical Cygwin bash prompt:

user@[EMAIL PROTECTED]
 ~
$

> 
> like
> D:\Example\Software\python>hello1.py
> 4
> 
> D:\Example\Software\python>cat hello1.py #!/usr/bin/python # 2007/02/08
> eric
> print 4
> D:\Example\Software\python>

There are a couple of ways to associate a file extension with an
aplication, but since awk requires a switch (-f) in front of the script
name, and usually other arguments as well, it doesn't make much (if any)
sense to make that association. I find it useful to associate the .awk
extension with my text editor so when I click on a script, it opens in the
editor where I can work on it.

You can associate the extension with a batch file

RUNAWK.CMD
@[EMAIL PROTECTED]
 -f%*

which inserts the -f switch and passes the entire argument string to gawk.

The easy way is to right click on a sample .awk file in Windows Explorer
or My Computer and select "Open with", then browse to gawk.exe and check
the "Always use ..." box before clicking on OK.

My advice is to do one or both of these things, but do not try to mix
them:

 A) learn and use the CMD interface provided as the default for XP and use
purely DOS/Windows syntax and conventions

 B) install and activate Cygwin, and use the bash/Linux-like environment,
syntax, and conventions.

If you chose A and need to use more than one computer, you can install
gawk (with its DLLs, or a stand-alone version from the Garbo archive) on a
flash drive.  Actually, you could install Cygwin that way, but it requires
manually finding and copying some DLLs, and creating a more sophisticated
startup batch file.

-- 

T.E.D. (tdavis@[EMAIL PROTECTED]
) MST (Missouri University of Science and
Technology)
used to be UMR (University of Missouri - Rolla).




 5 Posts in Topic:
How to using gawk in Windows
moonhkt <moonhkt@[EMAI  2008-05-09 10:36:27 
Re: How to using gawk in Windows
Hermann Peifer <peifer  2008-05-09 20:04:56 
Re: How to using gawk in Windows
Ted Davis <tdavis@[EMA  2008-05-09 15:28:37 
Re: How to using gawk in Windows
moonhkt <moonhkt@[EMAI  2008-05-09 20:01:36 
Re: How to using gawk in Windows
Ted Davis <tdavis@[EMA  2008-05-10 12:24:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 20:58:46 CDT 2008.