cancel
Showing results for 
Search instead for 
Did you mean: 

AWK Programming in Linux

Samuel Mathew
Frequent Advisor

AWK Programming in Linux

I am running a script that was made for HP-UX 10.20. We have ported this application to linux. IT has some awk commands in the script.
It shows the error close file
^parse error.
^ sign is coming underneath 'file'. ANybody has any idea what is happening.?
I would appreciate a quick answer from the expert s.
The script has been changed in some places to run uner linux. But this one we cant figure that out.
So please help me. If you need any more information please let me know
15 REPLIES
Balaji N
Honored Contributor

Re: AWK Programming in Linux

hey

are u using a awk file with all the commands and then calling it as

awk -f filename scriptname

or something similar.

if so check the filename.

some more inputs pls.

1. what is the name of the file it shows.
2. is it a data file or the commands file.

-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Samuel Mathew
Frequent Advisor

Re: AWK Programming in Linux

Balaji,
Thanks for the quick reply.
the error is like this:
awk: ../Drilling/awk/Drills:81: close file
^parse error
awk: ../Drilling/awk/Drills:81: close fTmp
^parse error
awk: ../Drilling/awk/Drills:81: close fDrill
^parse error
^sign comes under the file,fTmp and fDrill respectively.
Those are files defined like this in the script
file=Dir"/"Class[Cur]
fTmp=Dir"/tmp/Unsorted_"MILL
fDrill=Dir"/tmp/Drill_"MILL
So I assume that they are data files. I cant find them anywhere anyway

This is a tricky situation for me.
I would appreciate a help
Regards


Steven E. Protter
Exalted Contributor

Re: AWK Programming in Linux

Please post the script or relavent portions.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Balaji N
Honored Contributor

Re: AWK Programming in Linux

hmm..
too little info. if u could post snippets from the file with the error line indicated or the entire file, can have a look.

-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Samuel Mathew
Frequent Advisor

Re: AWK Programming in Linux

Thanks. Here isone of the script file.
If you can make out something from this, please let me know. There are a number of script files in this application that uses awk. I am a null on awk and sed as such.
Thanks
Bye
Stuart Browne
Honored Contributor

Re: AWK Programming in Linux

Simply put, try 'close(file)'.
One long-haired git at your service...
Krishna Prasad
Trusted Contributor

Re: AWK Programming in Linux

Also check the shell you are running in.

If you script calls awk within the shell, it maybe a shell issue.

On 10.20 you probably were using the corn ksh shell. On the Linux machine you probably are using bash or the posix shell.

Awk is also a little different since they were compiled on different Operating Systems.


One more suggestion is to start with one step of the script at a time. This may help indicated which section of the script is having the port issue.
Positive Results requires Positive Thinking
Samuel Mathew
Frequent Advisor

Re: AWK Programming in Linux

I am running ksh on this linux machine. Since the old scripts on HP-UX were on ksh I ran it on linux also to be on the safer side.
If I put set -vx at the top of the script will it help me to debug, the program better.
I have not tried the close(file) command yet. So are you suggesting that it is a syntax issue.
Any other comments?
Thanks
Sam
Samuel Mathew
Frequent Advisor

Re: AWK Programming in Linux

I could get rid of the errorwith awk. The suggestion to close(file) helped. I will be assigning points. Now
I have a problem with a function that is being called. I am attaching that here. The error is. "[0.00] Unexpected '.'
Can any of you help us with this. We suspect that this function attached here is causing it after we ran the scripts with set -vx.
I would appreciate help.
Regards

Stuart Browne
Honored Contributor

Re: AWK Programming in Linux

[ $G68 -ne 0 ] &&
binLinux/GenMill $Mill G68 $G68 "$Sign"
# printf 'G00 G90 G58 X0. Y0.\nG58 G68 X0 Y0 R%c[%0.3g]\n' "$Sign" "$G68"


These three lines are truely interseting.. The 'printf' might have been causing your error, but given the way these 3 lines are at the moment, I'd have expected something else, like a Syntax error.

This is obviously shell script, and you've not said which shell you're using. I'll assume bash or ksh for the moment.

The single [] around $G68 are using the external 'test' application, and assuming $G68 is numerical, should be fine. If it wasn't, you'd be getting "integer expression expected" errors on STDERR.

With the command on the next line after && however, this portion of the routine appears that it would never return the error you are describing.

You've siad you've run it with 'set -xv', then you should have seen exactally where it's falling over.

If you could paste us the output you get when using 'set -x' for when it calls this function, we might be able to help further.
One long-haired git at your service...
Samuel Mathew
Frequent Advisor

Re: AWK Programming in Linux

First of all, this is the snippet that calls the WriteOps function:

gawk ...
WriteOps
fi >> ${Mill}_$Func.nc
ReadOpLine $((OpN+1)) $Stat

And this is the output with set -vx

+ WriteOps
SquD: bin/Milling[129]:0.00:unexpected '.'
SquD: bin/Milling[129]:0.00:unexpected '.'
+ ReadOpLine 2 1

The 129th line of Milling is the last line of code in the file and simply states 'fi'

Thanks for all your help
Samuel Mathew
Frequent Advisor

Re: AWK Programming in Linux

First of all, this is the snippet that calls the WriteOps function:

WriteOps
fi >> ${Mill}_$Func.nc
ReadOpLine $((OpN+1)) $Stat

And this is the output with set -vx

+ WriteOps
SquD: bin/Milling[129]:0.00:unexpected '.'
SquD: bin/Milling[129]:0.00:unexpected '.'
+ ReadOpLine 2 1

The 129th line of Milling is the last line of code in the file and simply states 'fi'

Thanks for all your help
Stuart Browne
Honored Contributor

Re: AWK Programming in Linux

I don't suppose you'd be willing to provide all of this routine, so we can look at it from start-to-finish. we're just not getting enough information with the snippets you're providing.
One long-haired git at your service...
Samuel Mathew
Frequent Advisor

Re: AWK Programming in Linux

Stuart,
Sorry about that. I am attaching the full code of the routine that is giving the problem. I hope you the error that was coming which I had posted above. If you need any further input, I would be more than willing to give. IT is taking a lot of our time to transfer this script from HP-UX to Linux.
Thanks in advance.
Sam
Stuart Browne
Honored Contributor

Re: AWK Programming in Linux

Unfortunately, I can't see anything wrong with that script.

Modify the first line (#!/bin/ksh) to have a -x on the end of it, tne walk though to make sure each line gets the sorts of values you expect.
One long-haired git at your service...