Error with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error with awk
# 1  
Old 07-11-2013
Error with awk

i have been trying to run the following bash script, but get error:

awk: cmd. line:1: -
awk: cmd. line:1: ^ unexpected newline or end of string

I have been trying to figure out what the problem is but to no avail. I need to run the script urgently for a project, so any help will be highly appreciated!


input file (called 'input')
Code:
    0    13    1495.015    1495.02d0    3.03607E-09    0.000000    0.00000E+00
    0    14    1598.750    1598.57d0    1.90704E-09    0.000000    0.00000E+00
    0    15    1701.372    1700.87d0    1.26357E-09    0.000000    0.00000E+00
    0    16    1803.382    1802.22d0    9.11215E-10    0.000000    0.00000E+00
    0    17    1906.131    1904.54d0    7.17855E-10    0.000000    0.00000E+00
    0    18    2009.553    2007.55d0    5.88960E-10    0.000000    0.00000E+00
    0    19    2113.543    2110.84d0    4.86193E-10    0.000000    0.00000E+00
    0    20    2217.641    2214.16d0    4.09698E-10    0.000000    0.00000E+00
    0    21    2321.638    2317.24d0    3.53609E-10    0.000000    0.00000E+00
    0    22    2426.151    2420.84d0    3.12269E-10    0.000000    0.00000E+00
    0    23    2530.983    2524.70d0    2.80847E-10    0.000000    0.00000E+00
    0    24    2636.078    2629.18d0    2.52442E-10    0.000000    0.00000E+00


Code:
largesep_obs=103.188

avg_n="`awk '{sum_n+=$2} END{avg=sum_n/NR; print(avg)}' input`"

avg_ref="`awk '{sum_ref+=$3} END{avg=sum_ref/NR; print(avg)}' input`"

avg_obs="`awk '{sum_obs+=$4} END{avg=sum_obs/NR; print(avg)}' input`"

num="`awk -v avg_n=$avg_n -v avg_obs=$avg_obs '{sum+=($4-avg_obs)*($2-avg_n); print(sum)}' input`"

den="`awk -v avg_n=$avg_n '{sum+=($2-avg_n)**2}' input`"

largesep_ref=$num/$den

r=1

nu_not=2000

b="( $r*$largesep_ref/$largesep_obs-1 )*( $r*$avg_ref/$avg_obs-1 )**-1"

den_of_a=`awk -v avg_obs=$avg_obs -v avg_ref=$avg_ref -v nu_not=$nu_not -v b="$b" '{sum+=(($4/nu_not)**b)} END{ans=sum/NR; print(ans)}' input`

a=($avg_obs - $r*$avg_ref)/$den_of_a

no_of_rows=12

awk -v nu_not=$nu_not -v r=$r -v a=$a -v b=$b -v no_of_rows=$no_of_rows '\"{
            for (x=1; x<=no_of_rows; x++) {
            array[x]=r*$3 + a*(($4/nu_not)**b)
        print("%s", vector[x])
        print("\n")
            }            
}'\" input

# 2  
Old 07-11-2013
Quote all your variables and remove unnecessary backslash in your last awk code:
Code:
awk -v nu_not="$nu_not" -v r="$r" -v a="$a" -v b="$b" -v no_of_rows="$no_of_rows" '{
            for (x=1; x<=no_of_rows; x++) {
            array[x]=r*$3 + a*(($4/nu_not)**b)
        print("%s", vector[x])
        print("\n")
            }
}' input

# 3  
Old 07-11-2013
thanks! it kinda solved my original problem, but i was getting wrong results, so i modified two lines of code :

Code:
b=($r*$largesep_ref/$largesep_obs-1)/($r*$avg_ref/$avg_obs-1)
Code:
from
b="( $r*$largesep_ref/$largesep_obs-1 )*( $r*$avg_ref/$avg_obs-1 )**-1"

and

Code:
awk -v nu_not="$nu_not" -v r="$r" -v a="$a" -v b="$b" -v no_of_rows="$no_of_rows" '{
            array[NR]=r*$3 + a*(($4/nu_not)**b)
            print(array[NR], a, b)
}' input

from
Code:
awk -v nu_not=$nu_not -v r=$r -v a=$a -v b=$b -v no_of_rows=$no_of_rows '\"{             for (x=1; x<=no_of_rows; x++) {             array[x]=r*$3 + a*(($4/nu_not)**b)         print("%s", vector[x])         print("\n")             }             }'\" input

this gives me the following error :
Code:
./surface_corrections.sh: line 19: syntax error near unexpected token `('
./surface_corrections.sh: line 19: `b=($r*$largesep_ref/$largesep_obs-1)/($r*$avg_ref/$avg_obs-1)'

could you run the code and see what results u get? i expect a column of 12 numbers, which are intermediate between the third and fourth column values of my input file.
# 4  
Old 07-11-2013
Try to use shell arithmetics:
Code:
b=$(( ($r*$largesep_ref/$largesep_obs-1)/($r*$avg_ref/$avg_obs-1) ))

# 5  
Old 07-14-2013
There is no output in
Code:
den="`awk -v avg_n=$avg_n '{sum+=($2-avg_n)**2}' input`"

?
# 6  
Old 07-18-2013
Thanks guys, that helped me solving the problem!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Error in awk...

Hi friends... (Apoloigies for any typos.) (Don, thanks for your input.) Consider these two code snippets:- awkerror1.awk #!/usr/bin/awk -f BEGIN \ { SAWTOOTHPLUS64 = " !#$&\'\)*,-/0235689:<>?ABDEGHJKMNPQSTVWYZ\\^_abdeghjkmnpqstvwyz|}~" for(LOOP = 1; LOOP <= 13; ++LOOP) {... (3 Replies)
Discussion started by: wisecracker
3 Replies

2. UNIX for Dummies Questions & Answers

No error in awk...

Hi all... In the OSX forum I am starting a new awk project to learn awk. In this code snippet I have had to check boundaries to ensure that no NUMERICAL error occurs in the rest of the code... printf "Enter frequency required:- "; getline FREQ; RATE=(BYTES*FREQ); if ( RATE <= 4000 ) {... (4 Replies)
Discussion started by: wisecracker
4 Replies

3. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

4. Shell Programming and Scripting

awk Error

Hi I am trying to create a file with count of lines and string from shell variable, i am getting the error incorrect syntax. Below is the code : wc -l $filename | awk '{ print $1"|"$2"|"${SOURCETYPE} }'>>$AUDITFILENAME Could someone help me on this? (7 Replies)
Discussion started by: cnrj
7 Replies

5. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

6. Shell Programming and Scripting

AWK error

This is my disk space on solaris box and i wrote a simple script which identifies mount points which crosses 90% or above. But the AWK part is throwing some error and im unable to debug.. mzaheer @ UAT 144 % => df -k Filesystem kbytes used avail capacity Mounted on... (5 Replies)
Discussion started by: user__user3110
5 Replies

7. Shell Programming and Scripting

Awk error -- awk: 0602-562 Field $() is not correct.

typeset -i i=1 while read -r filename; do Splitfile=`$Targetfile_$i.txt` awk 'substr($0,1,5) == substr($filename,1,5) && substr($0,526,2) == substr($filename,6,2) && substr($0,750,12) == substr($filename,8,12)' $SourceFilename >> $Splitfile i=i+1 done < /tmp/list.out I am using this logic... (1 Reply)
Discussion started by: pukars4u
1 Replies

8. UNIX for Dummies Questions & Answers

awk error

Hi all, i have the files in the below sequence: fancy_LANG_STD_AU_2008-03-05.dat fancy_LANG_STD_HK_2008-03-06.dat fancy_LANG_STD_NZ_2008-03-05.dat fancy_STD_AU_2008-03-05.dat fancy_STD_HK_2008-03-06.dat fancy_STD_NZ_2008-03-05.dat i am trying to sort them like below: ... (3 Replies)
Discussion started by: gyankr
3 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

10. Shell Programming and Scripting

Error in awk

var1=`echo "emp,dept,salgrade" | awk -F, '{print NF}'` count=1 while ; do i=`expr $count` tname=`echo "emp,dept,salgrade" | awk -F, '{ print $(echo $i) }'` count=$count+1; echo ${tname}; echo $count done I want to store in tname=emp, tname=dept,tname=salgrade I am getting... (2 Replies)
Discussion started by: dreams5617
2 Replies
Login or Register to Ask a Question