LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 06-25-2010, 12:22 PM   #1
tanggo81
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Rep: Reputation: 0
Execution of awk script gives error message for invalid character


Hi,

I have installed cygwin in a vista platform and tried to run an awk script from the shell but I got an error message pointing that the single qoute as invalid character. Here is the codes I used:

#! /bin/sh
#
awk 'BEGIN {
xmin = 100000.
xmax = -100000.
ymin = 100000.
ymax = -100000.
zmin = 100000.
zmax = -100000.
xsum = 0.
ysum = 0.
zsum = 0.
xpoints = 0
ypoints = 0
zpoints = 0
atom_total = 0
add = 5.0
passo = 0.375
}
$1 ~ /ATOM|HETATM|atom|hetatm/ {
x[atom_total] = substr($0,31,8) + 0.
y[atom_total] = substr($0,39,8) + 0.
z[atom_total] = substr($0,47,8) + 0.

xsum += x[atom_total]
ysum += y[atom_total]
zsum += z[atom_total]

atom_total++
}
END {
if ( atom_total != 0 ) {
xmean = xsum / atom_total
ymean = ysum / atom_total
zmean = zsum / atom_total
#
# Loop over atoms in molecule to find the xyz-coordinates of
# the atom nearest the mean xyz-coordinates of the whole
# molecule...
#
dmin = 100000.
for (i=0; i<atom_total; i++) {
dx = x[i] - xmean
dy = y[i] - ymean
dz = z[i] - zmean
d2 = dx*dx + dy*dy + dz*dz
if (d2 < dmin) {
dmin = d2
centralatom = i
}
if (x[i] < xmin) {
xmin = x[i]
}
if (x[i] > xmax) {
xmax = x[i]
}
if (y[i] < ymin) {
ymin = y[i]
}
if (y[i] > ymax) {
ymax = y[i]
}
if (z[i] < zmin) {
zmin = z[i]
}
if (z[i] > zmax) {
zmax = z[i]
}
}

dx_max = xmax - xmin
dy_max = ymax - ymin
dz_max = zmax - zmin

max = -100000
if (dx_max > max) {
max = dx_max
}
if (dy_max > max) {
max = dy_max
}
if (dz_max > max) {
max = dz_max
}

xmin -= max/2
ymin -= max/2
zmin -= max/2
xmax += max/2
ymax += max/2
zmax += max/2
#xmin -= add
#ymin -= add
#zmin -= add
#xmax += add
#ymax += add
#zmax += add

xpoints = (xmax-xmin)/passo
ypoints = (ymax-ymin)/passo
zpoints = (zmax-zmin)/passo

printf("=========================== Cut from the line below ========================\n")
printf("REMARK Box file to be displayed in any molecule visualizer\n")
printf("REMARK Atoms 1-8 are the vertex of the box\n")
printf("REMARK Atom 9 is the center of the box\n")
printf("REMARK gridcenter %.3f %.3f %.3f\t#xyz-coordinates or \"auto\"\n", xmean, ymean, zmean)
printf("REMARK npts %d %d %d\t\t\t# num.grid points in xyz\n", xpoints, ypoints, zpoints)
printf("REMARK\n")
printf("HETATM 1 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymax,zmax)
printf("HETATM 2 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymax,zmax)
printf("HETATM 3 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymin,zmax)
printf("HETATM 4 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymin,zmax)
printf("HETATM 5 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymax,zmin)
printf("HETATM 6 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymax,zmin)
printf("HETATM 7 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymin,zmin)
printf("HETATM 8 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymin,zmin)
printf("HETATM 9 C BOX 1 %7.3f %7.3f %7.3f\n", xmean, ymean, zmean)
printf("CONECT 1 5 3 2\n")
printf("CONECT 2 1 4 6\n")
printf("CONECT 3 1 4 7\n")
printf("CONECT 4 3 2 8\n")
printf("CONECT 5 1 6 7\n")
printf("CONECT 6 5 2 8\n")
printf("CONECT 7 5 3 8\n")
printf("CONECT 8 4 6 7\n")
printf("END\n")
printf("=========================== to the line previous this one ========================\n")
printf("\n")
printf("\n")
printf("\n")
printf("\t\t ... and paste into a text file named box.pdb\n")

}
}' $1




and here is the error message that I recieved:
awk: awk 'BEGIN {
awk: awk ^ invalid char ''' in expression

I tried to change the single qoute to double qoute at the beginning and the end of the script but it ended up with an error like this:
awk: awk "BEGIN {
awk: awk ^ unterminated string

Am I missing something or done anything wrong in the code?
Thanks.
 
Old 06-25-2010, 03:36 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
How are you invoking the script? Because this isn't an awk script, it's a shell script that contains an awk command. I created a similar short test script just now, and when I tried to run it with "awk -f scriptname", I got a similar error.

Speaking of which, from the output above (and you really should enclose it in [code][/code] tags), your #!/bin/sh "shebang" line has an unnecessary space in it.
 
Old 06-26-2010, 02:35 AM   #3
tanggo81
LQ Newbie
 
Registered: Jun 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the advice. Here is the way I executed the script:

Code:
awk -f scriptname inputfile
 
  


Reply

Tags
awk, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
awk error 'Invalid collation character: ' Mash Programming 1 04-15-2007 01:44 AM
Failed to open device gt68xxLlibusb 004:002 invalid arguments error message radatan71 Linux - Hardware 1 10-24-2005 08:07 PM
script execution error linux_lover2005 Programming 3 12-22-2004 06:46 AM
gaim v.79 for mdk 10: do u get an error message saying signature invalid? webazoid Linux - Software 0 07-04-2004 12:21 AM
CUPS - 127 character error message psalm Linux - Software 1 01-13-2004 10:39 AM


All times are GMT -5. The time now is 02:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration