View Single Post
  #6  
Old 03-27-2007, 01:33 AM
unix unix is offline
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default Re: AWK for Windows XP?

On Mon, 26 Mar 2007 15:58:51 -0400, "aleu@vp.pl" wrote:

>Matthias Tacke wrote:
>>
>> http://gnuwin32.sourceforge.net/packages/gawk.htm
>> http://unxutils.sourceforge.net/

>
>Matthias,
>
>Thanks a million for this links. I have tried the following command:
>
>C:\test>cat test.txt | gawk '{ print $11 }'
>gawk: cmd. line:1: '{
>gawk: cmd. line:1: ^ invalid char ''' in expression
>cat: write error: Invalid argument
>
>What am I doing wrong here? I want to display the 11th column of the
>test.txt file.
>


In Windows, it's
awk "{print $11}" test.txt

Even in Unix, that is a misuse of cat - awk scripts take filenames as
arguments, and can be much more useful if the file is passed as an
argument since the FILENAME variable is then the name of the file
being processed, multiple files can be distinguished from each other,
and the input file can even be determined in a BEGIN{} block.

Another interesting point about gawk and Windows: if a filespec is to
be interpreted by gawk, use / as the directory separator (inside
scripts, and as the argument to -f on the command line) but if they
are to processed by the command interpreter, specifically the files
passed as arguments to the program, use \ - use \\ in strings literal
that are to be passed as part of a system() or command | getline
construct.

--
T.E.D. (tdavis@gearbox.maem.umr.edu) Remove "gearbox.maem" to get real address - that one is dead
Reply With Quote