expr: syntax error


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers expr: syntax error
# 1  
Old 04-16-2010
expr: syntax error

Hi All,

This is a piece of code from one of my scripts:


Code:
t1=`cat temp3.21447 | grep WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG | awk '{print $3}' | cut -c1-5`
t2=`cat temp3.21447 | grep WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG | awk '{print $5}' | cut -c1-5`
 
#t1=23:43
#t2=23:40
        shr=`echo $t1 | cut -c1-2`
        smin=`echo $t1 | cut -c4-5`
        stot=`expr $shr \* 60`
        stot=`expr $stot + $smin`
        ehr=`echo $t2 | cut -c1-2`
        emin=`echo $t2 | cut -c4-5`
        etot=`expr $ehr \* 60`
        etot=`expr $etot + $emin`
        if [ $stot -gt $etot ]
        then
        etot=`expr $etot + 1440`
        fi
        diff=`expr $etot - $stot`

its giving me 3 times syntax error, though its giving the desired result. but this error is very annoying.
Code:
expr: syntax error
expr: syntax error
expr: syntax error

I'm using #!/bin/ksh
at the top of my script. Pls help.Thanks

Last edited by pludi; 04-16-2010 at 03:09 AM.. Reason: code tags, please...
# 2  
Old 04-16-2010
i hope you have some undefined variables used in expr, thats why you get this syntax error.
# 3  
Old 04-16-2010
Hi.

I would surround the identified area of the script with:
Code:
set -x
...
set +x

as a kind of trace that will show you commands as they are executed. That should get you farther ... cheers, drl
# 4  
Old 04-16-2010
You can replace this snippet of your code with all the cat, awk, cut, grep and expr commands:
Code:
t1=`cat temp3.21447 | grep WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG | awk '{print $3}' | cut -c1-5`
t2=`cat temp3.21447 | grep WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG | awk '{print $5}' | cut -c1-5`
 
#t1=23:43
#t2=23:40
        shr=`echo $t1 | cut -c1-2`
        smin=`echo $t1 | cut -c4-5`
        stot=`expr $shr \* 60`
        stot=`expr $stot + $smin`
        ehr=`echo $t2 | cut -c1-2`
        emin=`echo $t2 | cut -c4-5`
        etot=`expr $ehr \* 60`
        etot=`expr $etot + $emin`
        if [ $stot -gt $etot ]
        then
        etot=`expr $etot + 1440`
        fi
        diff=`expr $etot - $stot`

with one awk command:
Code:
diff=`awk '/WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG/{
  t1=sub($3,1,5)
  t2=sub($5,1,5)
  split(t1,s,":")
  split(t2,e,":")
  stot=s[1] * 60 + s[2]
  etot=e[1] * 60 + e[2]
  if(stot > etot){ etot+=1440 }
  print etot - stot
}
' temp3.21447`

echo $diff

Regards
# 5  
Old 04-16-2010
It would be interesting to see the output from this command:

Code:
cat temp3.21447 | grep WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG

# 6  
Old 04-16-2010
expr issue

Code:
t1=`cat temp3.21447 | grep WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG | awk '{print $3}' | cut -c1-5`

try like this

Code:
t1=`cat temp3.21447 | grep 'WEALTHTOUC_TRANS_20100409_233127.txt.txt.TRG' | awk '{print $3}' | cut -c1-5`


Last edited by Franklin52; 04-18-2010 at 08:43 AM.. Reason: Please use code tags, thank you
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expr: non-numeric argument syntax error on line 1, teletype

Hi, I tried to look up the issue i'm experiencing, but i'm confused what's wrong with my script. After executing the script I'm getting the following error expr: non-numeric argument syntax error on line 1, teletype After some research, it seems that the problem relates to bc. I have... (1 Reply)
Discussion started by: nms
1 Replies

2. Homework & Coursework Questions

How to lclear "expr: syntax error" eventhough everything looks fine?

Hi All, As per my knowledge in unix, my code looks fine. But still I am getting error (expr:syntax error). Please help me to resolve this error. Script : PRE_LBNO=0 PRE_DATE=0 TOT_PAY=0 TOT_REM=0 TOTAL=1 for Record_Type in `cut -c 1 Inputt.dat` do if ; then CURR_LBNO=` cut -c... (6 Replies)
Discussion started by: lathanandhini
6 Replies

3. Shell Programming and Scripting

Error with expr - "expr: syntax error"

Hi All, I'm writing a shell script in KSH, where I want to store the filename, total record count and actual record count of all the source files. The source files reside in 4 different sub-folders under the same root folder. Below is code: #!/usr/bin/ksh... (6 Replies)
Discussion started by: jagari
6 Replies

4. Shell Programming and Scripting

Expr Syntex error

Hello, I am new to Shell programing. I want to add two numbers & show result. command I use are as under Echo Enter the two numbers read number d1 = ` expr $ num%10` num = `expr $ num/10` d2 = ` expr $ num%10` num = `expr $ num/10` sum = $ d1 + $ d2 echo the sum is $ sum I am getting... (1 Reply)
Discussion started by: pbchhaya
1 Replies

5. Shell Programming and Scripting

expr/bc syntax issue

Hi, I am facing issues in my shell script while trying to add two variables. Look at the snippet below for details: # Initially variable SAMPLE1 and SAMPLE2 are set from different sources. Have trucated decimal to avoid numeric errors in expr SAMPLE1=`/usr/bin/top -n 1 | head -3 | tail -1... (3 Replies)
Discussion started by: animesh303
3 Replies

6. UNIX for Dummies Questions & Answers

expr - Syntax error

hello to everyone, i am writing a shell script in unix and i use the following command: lnum= cut -f 1 -d : aa passline=`expr $lnum + 1` echo "$passline" with the following command i get the value that is stored in the first field of the file "aa" and i save it in the variable "lnum". i am... (2 Replies)
Discussion started by: omonoiatis9
2 Replies

7. Shell Programming and Scripting

expr error in ksh

Hi ALL, i am so much confused y the following script is not working in the korn shel which works in bash shell. please solve the error that i am facing. i want to extract the format of the size from a variable i.e. GB or KB or MB or B or BYTES code: -------- size_dir_pass=1.2gb... (2 Replies)
Discussion started by: G.K.K
2 Replies

8. UNIX for Dummies Questions & Answers

expr syntax

HELLO i have a problem i need to do this equation: final_result=*1.5. I am using expr like this: FINAL_RESULT=`expr (($RESULT1 + $RESULT2 / 2) \* 3) / 2` but it is wrong. Someone help me.thank you (2 Replies)
Discussion started by: psalas
2 Replies

9. Shell Programming and Scripting

getting error with expr

sum=0; cat op_api2 |while read word1 word2; do echo $word2 sum=`expr $word2 + $sum`; done echo $sum op_api2 ( file has this data ) ---------------------------- UsageSummary 1034 UsageSummary 1675 UnbilledUsage 175 UnbilledUsage 177 UnbilledUsage 177 UnbilledUsage 194 I want the... (2 Replies)
Discussion started by: bishweshwar
2 Replies

10. Shell Programming and Scripting

expr: syntax error. why?

i want to get a substring from a string and used such shell script: var_year=`expr substr "07132006" 5 4` echo $var_year but i got such error message: expr: syntax error. why? Note: Kshell used on solaris 8. :confused: (5 Replies)
Discussion started by: robin.zhu
5 Replies
Login or Register to Ask a Question