Problem with running awk script in pbs file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with running awk script in pbs file
# 1  
Old 03-07-2012
Problem with running awk script in pbs file

Hi guys I have a problem with one module of my script. It's awk script running in pbs file - It's working when I make a call from pbs to separate awk only file like this
Quote:
awk -f OW-out.awk <snapshot0.pdb>OW-snap0
but when I try to execute this code in pbs file it fails
Code:
awk 'BEGIN { max = -1000; min = 1000 }
{
{$4 == "TCO"} 
    {value = $5 ~ /^[[:alpha:]]$/ ? $9 : $8;  
    max = max < value ? value : max;
    min = min > value ? value : min;
    $3 == "OW" && ($8 >min && $8 <max || $8 == min || $8 == max )} {print NR, $2, $3, $5, $6, $7, $8}
 }' snap0.pdb>snap0-OW

It executes only this command
Code:
{print NR, $2, $3, $5, $6, $7, $8}

Here#s example of input
Code:
ATOM   4685  HB1 PRO A 322      23.988  40.451 115.223  1.00  0.00            
ATOM   4686  HB2 PRO A 322      25.018  39.501 116.373  1.00  0.00            
ATOM   4687  CG  PRO A 322      22.858  39.661 116.803  1.00  0.00            
ATOM   4688  HG1 PRO A 322      21.968  39.931 116.223  1.00  0.00            
ATOM   4689  HG2 PRO A 322      22.878  38.581 116.893  1.00  0.00            
ATOM   4690  CD  PRO A 322      22.728  40.201 118.313  1.00  0.00            
ATOM   4691  HD1 PRO A 322      21.718  40.511 118.563  1.00  0.00            
ATOM   4692  HD2 PRO A 322      23.008  39.401 119.013  1.00  0.00            
ATOM   4693  C   PRO A 322      23.858  42.771 116.393  1.00  0.00            
ATOM   4694  O1  PRO A 322      24.688  43.721 116.293  1.00  0.00            
ATOM   4695  O2  PRO A 322      22.628  42.691 115.973  1.00  0.00            
ATOM   4696  C1  TCO B 323      90.664  64.841 42.383  1.00  0.00            
ATOM   4697  C2  TCO B 323      90.074  64.211 65.623  1.00  0.00            
ATOM   4698  C3  TCO B 323      89.624  62.731 65.433  1.00  0.00            
ATOM   4699  C4  TCO B 323      88.894  62.251 166.673  1.00  0.00            
ATOM   4700  C5  TCO B 323      88.634  60.761 166.523  1.00  0.00            
ATOM   4701  C6  TCO B 323      88.114  60.131 167.803  1.00  0.00            
ATOM   4702  O7  TCO B 323      88.854  59.851 168.753  1.00  0.00 
   ATOM  46103  HW1 SOL  7981      30.758  -0.449  19.783  1.00  0.00            
ATOM  46104  HW2 SOL  7981      31.818   0.771  19.533  1.00  0.00            
ATOM  46105  OW  SOL  7982      15.138  42.461  20.343  1.00  0.00            
ATOM  46106  HW1 SOL  7982      15.858  42.321  21.013  1.00  0.00            
ATOM  46107  HW2 SOL  7982      15.178  41.731  19.663  1.00  0.00            
ATOM  46108  OW  SOL  7983      63.308  14.411   0.803  1.00  0.00            
ATOM  46109  HW1 SOL  7983      63.438  15.351   0.483  1.00  0.00            
ATOM  46110  HW2 SOL  7983      63.988  13.811   0.383  1.00  0.00            
ATOM  46111  OW  SOL  7984      12.378   9.411  91.843  1.00  0.00            
ATOM  46112  HW1 SOL  7984      12.948   8.621  92.073  1.00  0.00            
ATOM  46113  HW2 SOL  7984      12.158   9.911  92.683  1.00  0.00            
ATOM  46114  OW  SOL  7985       9.468  59.311 104.643  1.00  0.00            
ATOM  46115  HW1 SOL  7985       8.768  59.691 105.253  1.00  0.00            
ATOM  46116  HW2 SOL  7985      10.368  59.681 104.903  1.00  0.00            
ATOM  46117  OW  SOL  7986       4.488  32.241  44.263  1.00  0.00            
ATOM  46118  HW1 SOL  7986       4.308  31.791  45.143  1.00  0.00            
ATOM  46119  HW2 SOL  7986       3.738  32.871  44.063  1.00  0.00            
ATOM  46120  OW  SOL  7987      64.378  17.281 231.638  1.00  0.00            
ATOM  46121  HW1 SOL  7987      64.078  18.161 231.278  1.00  0.00            
ATOM  46122  HW2 SOL  7987      65.288  17.371 232.028  1.00  0.00            
ATOM  46123  OW  SOL  7988      21.098  12.041  64.393  1.00  0.00            
ATOM  46124  HW1 SOL  7988      21.628  12.571  63.743  1.00  0.00            
ATOM  46125  HW2 SOL  7988      21.648  11.851  65.203  1.00  0.00            
ATOM  46126  OW  SOL  7989      89.154  23.561 223.108  1.00  0.00            
ATOM  46127  HW1 SOL  7989      88.994  22.571 223.118  1.00  0.00            
ATOM  46128  HW2 SOL  7989      90.094  23.751 222.838  1.00  0.00            
ATOM  46129  OW  SOL  7990      18.518  62.281  68.303  1.00  0.00            
ATOM  46130  HW1 SOL  7990      19.398  62.621  67.953  1.00  0.00            
ATOM  46131  HW2 SOL  7990      18.678  61.771  69.153  1.00  0.00            
ATOM  46132  OW  SOL  7991      82.328  54.771  23.723  1.00  0.00            
ATOM  46133  HW1 SOL  7991      81.528  54.791  23.123  1.00  0.00            
ATOM  46134  HW2 SOL  7991      83.138  54.531  23.183  1.00  0.00            
ATOM  46135  OW  SOL  7992      14.968  30.861 133.363  1.00  0.00            
ATOM  46136  HW1 SOL  7992      15.528  31.181 132.603  1.00  0.00            
ATOM  46137  HW2 SOL  7992      15.548  30.471 134.083  1.00  0.00            
ATOM  46138  OW  SOL  7993       2.928  50.331  47.593  1.00  0.00            
ATOM  46139  HW1 SOL  7993       3.828  50.241  47.173  1.00  0.00            
ATOM  46140  HW2 SOL  7993       2.428  49.471  47.493  1.00  0.00            
ATOM  46141  OW  SOL  7994      24.828  65.181 253.138  1.00  0.00            
ATOM  46142  HW1 SOL  7994      24.738  64.991 252.168  1.00  0.00            
ATOM  46143  HW2 SOL  7994      24.078  64.741 253.638  1.00  0.00            
ATOM  46144  OW  SOL  7995      29.148  19.901 135.113  1.00  0.00            
ATOM  46145  HW1 SOL  7995      28.678  19.251 135.713  1.00  0.00            
ATOM  46146  HW2 SOL  7995      29.698  20.521 135.663  1.00  0.00            
ATOM  46147  OW  SOL  7996      45.958   2.891  59.383  1.00  0.00            
ATOM  46148  HW1 SOL  7996      46.428   3.661  58.953  1.00  0.00

Thanks for Your time!
Take care,
grincz

Last edited by pludi; 03-08-2012 at 03:34 AM.. Reason: added file example
# 2  
Old 03-07-2012
I don't think your code blocks are doing what you think they do. Some of them look pointless (a code block that does only $4=="TCO" ? You probably meant to use () instead of {}, and put it outside), some of them look misplaced. And frequently, both. I don't think you can nest them in that fashion, if you want the blocks to be dependent on logic you either need an if() before or have them outside of any other block.

I'll rearrange it as best I can, but your code isn't commented, so I may not understand its true intent.
Code:
awk 'BEGIN { max = -1000; min = 1000 }
# Run this code block whenever $4 == "TCO"
# The { must follow immediately after, not on the next line.
$4 == "TCO" { 
    value = $5 ~ /^[[:alpha:]]$/ ? $9 : $8;  
    max = max < value ? value : max;
    min = min > value ? value : min; }

# Run this code block whenever conditions match
($3 == "OW") && ($8 >min && $8 <max || $8 == min || $8 == max ) { 
print NR, $2, $3, $5, $6, $7, $8}' snap0.pdb>snap0-OW

Thank you for attaching example input, but example input is useless without example output too. We won't have any idea if the program actually does what you want...
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-08-2012
It made the work done! Thanks a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pbs script path from the id

Is it possible to lookup the path to the pbs script by Job ID? I cannot find the answer anywhere. (3 Replies)
Discussion started by: coppuca
3 Replies

2. Shell Programming and Scripting

Problem running db2 commands in awk

Hi , I am trying to use the below in awk but failed, any one assist please, awk '{ print $0; if ( $0 ~ /LOADTMP1/ ) { print $4; Table_name=system($( db2 -x "SELECT TRIM(TD.BSCHEMA) || '.' || TRIM(TD.BNAME) AS TABLE_NAME FROM SYSCAT.TABDEP TD WHERE TD.BTYPE='T' AND... (2 Replies)
Discussion started by: Nandy
2 Replies

3. Shell Programming and Scripting

Problem running awk script in Debian 6.0.2

Hello to all, May be some expert could help me. I have the below awk script that works correctly in Cygwin: awk -F\" 'FNR==NR && FNR>1 {gsub(",","",$5); N=$5;next} $10 in N && FNR>1 { Y=$8 Z=(N==$8)?"Yes:"No"; } END{ for(k in N) {print k,Y,N,Z?Z:"Not_Found"} }' file2 file1But when I... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

4. Shell Programming and Scripting

Problem on running a script

Hi all, Running follow command on terminal; $ glance -T cloudlive -I ubuntu -K ubuntu123 -N \ http://127.0.0.1:5000/v2.0/OpenX add name="cirros" is_public=true \ container_format=ovf disk_format=raw < \ /srv/cirros-0.3.0-x86_64-disk.img It works without problem. Putting it on a... (5 Replies)
Discussion started by: satimis
5 Replies

5. Shell Programming and Scripting

script to tail file; problem with awk and special characters

Trying to use code that I found to send only new lines out of a log file by doing: while :; do temp=$(tail -1 logfile.out) awk "/$last/{p=1}p" logfile.out #pipe this to log analyzer program last="$temp" sleep 10 done Script works fine when logfile is basic text, but when it contains... (2 Replies)
Discussion started by: moo72moo
2 Replies

6. Shell Programming and Scripting

Problem running a program/script in the background from a script

Hi all, I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes... (5 Replies)
Discussion started by: newbie_01
5 Replies

7. Shell Programming and Scripting

Problem with running the remote script

Hi All, I am running a script which is present on remote machine using ssh command. the remote script is failing when try to load a property file. It says file does not exist. Any idea what should be the problem for this. Thanks Supriya. (7 Replies)
Discussion started by: supriyabv
7 Replies

8. UNIX for Dummies Questions & Answers

problem running script

hey, i'm trying to run several processes due 2 loops : the code is: cd ${TIBCO_HOME}/tra/domain/${DOMAIN}/application/ for app_name in ls * do echo $app_name if && && ; then exit else echo $app_name cd $app_name pwd for ps_name in ls *.sh do echo... (2 Replies)
Discussion started by: ohadr
2 Replies

9. UNIX for Advanced & Expert Users

Problem in running an AWK script

Hi Everyone, I am required to write an AWK script that can be run from any directory. This script finds subscription rates for each subscriber at an interval of 10 mins. I want that just by copy pasting the whole script in shell prompt and giving the input arguments, script must work. Currenty... (4 Replies)
Discussion started by: rachana8p
4 Replies

10. Shell Programming and Scripting

Problem in Running Script

Hi friends, i have written one small script named as "size.sh"..... while running its giving syntax error at line no 2: 'str=$' unexpected. How to run this file ??? please help me. file content is : ----------------------------- #!/bin/sh str=$( df -k | grep /usr/local)... (14 Replies)
Discussion started by: samfrance
14 Replies
Login or Register to Ask a Question