Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gawk for windows error

Status
Not open for further replies.

dbase77

Technical User
Apr 23, 2002
591
0
0
IE
Hi,

I installed gawk for windows. When I tried to run the same awk command that I was using from Unix, I got error below. Am I missing something here? Thanks.

C:\Program Files\GnuWin32\bin>gawk 'length($0)<100{$0=sprintf("%-100s",$0)}1' input_file > output_file
The system cannot find the file specified.

 


What is it you do not understand about "[red]The system cannot find the file specified.[/red]"?

May it be that the input_file is not in the C:\Program Files\GnuWin32\bin directory?

[noevil]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Hi,

The input_file is in the directory. This confuse me, why windows system giving out that error. Do you thing I used the wrong gawk command?

Thanks.
 
Can you post the output of
Code:
C:\Program Files\GnuWin32\bin>dir input_file
C:\Program Files\GnuWin32\bin>gawk '{print}' input_file
preferably using cut and paste

Ceci n'est pas une signature
Columb Healy
 
Hi,

C:\Program Files\GnuWin32\bin>dir input_file
Volume in drive C has no label.
Volume Serial Number is C470-36AC

Directory of C:\Program Files\GnuWin32\bin

25/09/2007 12:33 1,935 input_file
1 File(s) 1,935 bytes
0 Dir(s) 9,652,367,360 bytes free

C:\Program Files\GnuWin32\bin>gawk '{print}' input_file
gawk: cmd. line:1: '{print}'
gawk: cmd. line:1: ^ invalid char ''' in expression

C:\Program Files\GnuWin32\bin>

 
Hi

Yep, there you have the reason. The [tt]cmd[/tt] does not parse the single quote ( ' ) as quotation mark and pases it directly to the [tt]awk[/tt]. And as we know, together with the single quotes that line is not valid [tt]awk[/tt] syntax.

I suggest to install CygWin to have a complete Linux environment for your tools, together with [tt]bash[/tt] and [tt]ksh[/tt].

Feherke.
 
Hmm...

Does Windows gawk dislike the single quote?
What does
Code:
gawk "{print}" input_file
do?

Ceci n'est pas une signature
Columb Healy
 
With gawk for windows ALWAYS use the -f option

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Any other way I could do this without installing cgywin? Internet is not an option here. Thanks.
 
Yes, create a file containing the awk program and use the -f option of the gawk command.

BTW, you've asked in an UNIX forum !

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

Columb said:
Does Windows gawk dislike the single quote?
No. All [tt]awk[/tt] implementations dislike getting a bare single quote ( ' ) in their face. The Unix equivalent of the test line you suggested would be like this :
Code:
[blue]master #[/blue] awk "'{print}'" input_file
awk: syntax error near line 1
awk: bailing out near line 1


Feherke.
 
columb,

using double quote seems OK. But how do I use it for my script?


PHV,

using -f I still got error about single quote. Any idea? I paste my script inside a file and run:

gawk -f gawkfile

C:\Program Files\GnuWin32\bin>gawk -f gawkfile
gawk: gawkfile:1: 'length($0)<100{$0=sprintf("%-100s",$0)}1' input_file > output_file
gawk: ffb.txt:1: ^ invalid char ''' in expression

 
Hi

Put this in the file :
Code:
length($0)<100{$0=sprintf("%-100s",$0)}1
and this in the command line :
Code:
[blue]C:\Program Files\GnuWin32\bin>[/blue]gawk -f gawkfile input_file > output_file

Feherke.
 
Sorry for posting in UNIX. I thought since I copy awk from UNIX, somebody in here could give me some answer.

Should I move it to awk forum under programmer?
 
gawkfile:
length($0)<100{$0=sprintf("%-100s",$0)}
1

command line:
gawk -f gawkfile input_file > output_file

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'd loose the quotes inside the gawkfile and the in/out file needs to be on the gwak command line:

gawkfile:
length($0)<100{$0=sprintf("%-100s",$0)}1

commandline:
gawk -f gawkfile inputfile > output_file

(I dind't test it like this, but it would make sense to me)


HTH,

p5wizard
 
Hi,

Thanks everybody for helping me. Really appreciate it.
 
Putting a program on the command-line is usually harder in windows than under unix. This should work.

gawk "length($0)<100{$0=sprintf(\"%-100s\",$0)}1" input_file

If you have mawk, try

mawk "length($0)<100{$0=sprintf('%-100s',$0)}1" input_file

Another way to feed a program to awk:

echo length($0)<100{$0=sprintf("%-100s",$0)}1|awk -f - file

Windows doesn't recognize ' as a quote character, so if it sees < it thinks input-redirection from a file is called for. So although Ruby, for example, allows this:
[tt]ruby -e 'puts 8*2'[/tt]
you have to make sure you don't use < or > or |.
 
The more I think about it the more I agree with feherke that, if you're used to Unix, then the Cygwin route is the one to take. I don't want to start a flame war but bash/ksh is so much more powerful than cmd and you'll know your scripts will work.

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top