![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Problem with dividing
Hi All, I have two variables like below.. Code:
ETIMEHR =03 #END TIME HOUR ETIMEMIN=02 #END TIME MIN Now I'm converting the min to hour by deviding it by 60 Code:
ETIMEMINCONV=`echo "scale=2; $ETIMEMIN/60" | bc` but when i print ETIMEMINCONV instead of getting converted value i'm getting an error like "syntax error on line 1" I'm using this inside for loop.. so for some values it is working and for others it is giving the above said error... is there any other alternative for this? thanks®ards, Deepak. |
|
|||
|
Can you show more (like "the loop")? For which values is it not working? Can you run the script with -x (set -x) to start debugging the problem?
(I trust that the space before the = in "ETIMEHR =03" is not really there in your actual script) |
|
|||
|
I did a test... Code:
$ cat Test set -x X=1 for I in 1 2 3 4 5 6 7 8; do X=$(echo "scale=2; $X/$I" | bc) echo $X $I done $ ./Test + X=1 + + bc + echo scale=2; 1/1 X=1.00 + echo 1.00 1 1.00 1 + + echo scale=2; 1.00/2 + bc X=.50 + echo .50 2 .50 2 ... If bc gives an error you should see it among this output. Just before that you should see the value of ETIMEMIN (i.e. "echo scale=2 .....") that was used in the "echo ... | bc" command. If you are able to show the code for the loop (and anything else needed within it) then it would made it easier. |
|
|||
i dont have the exact code with me now.. It is there in my office system. i will do as per your suggestion tomorrow and let you know.. Thanks a lot for your advice. ---------- Post updated at 05:36 PM ---------- Previous update was at 05:29 AM ---------- hi scottn Code:
ENDDAY=11/25/09
+ + echo 11/25/09
ENDMM=11/25/09
+ + awk -F/ {print $2}
+ echo 11/25/09
ENDDD=25
+ + awk -F/ {print $3}
+ cut -c1-2
+ echo 11/25/09
ENDYY=09
+ + grep -i $PATH
+ awk -F; {print $21}
+ awk -F {print $2}
+ awk -F: {print $1}
+ sort -u
ETIMEHR=06
+ + awk -F; {print $21}
+ awk -F: {print $2}
+ grep -i $PATH
+ sort -u
+ awk -F {print $2}
ETIMEMIN=02
+ + bc
/60cho scale=2;02
ETIMEMINCONV=syntax error on line 1,
+ print syntax error on line 1,
syntax error on line 1,
this is what the error i'm getting.. see there it is taking /60 at the beginning instead of 02/60... pls help me.. ---------- Post updated at 07:20 PM ---------- Previous update was at 05:36 PM ---------- For some values i'm getting the proper ans as shown below.. Code:
+ grep -i $PATH
+ awk -F; {print $21}
+ cut -d -f1
+ sed -e s/\$/ /g
ENDDAY=11/30/09
+ + echo 11/30/09
ENDMM=11/30/09
+ + awk -F/ {print $2}
+ echo 11/30/09
ENDDD=30
+ + awk -F/ {print $3}
+ echo 11/30/09
+ cut -c1-2
ENDYY=09
+ + awk -F; {print $21}
+ awk -F: {print $1}
+ grep -i $PATH
+ sort -u
+ awk -F {print $2}
ETIMEHR=09
+ + grep $PATH
+ awk -F; {print $21}
+ awk -F {print $2}
+ awk -F: {print $2}
+ sort -u
ETIMEMIN=51
+ X=51
+ + bc
+ echo scale=2; (51/60)
ETIMEMINCONV=.85
+ print .85
.85
so please tell me what is wrong with this... Last edited by smarty86; 11-30-2009 at 11:17 PM.. |
|
|||
|
hey i dont know what was wrong.. i just multiplied first by 1000 to the value of ETIMEMIN then instead of deviding by 60 i used 60000..so it is working fine now
![]() Thanks for all your reply... |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dividing single file by lines? | anoc | Shell Programming and Scripting | 1 | 04-08-2008 02:08 PM |
| scipt dividing strings /reg expr | maco_home | UNIX for Dummies Questions & Answers | 3 | 08-30-2007 10:39 AM |
| Dividing float values | shash | UNIX for Dummies Questions & Answers | 3 | 01-17-2007 05:37 AM |
| dividing a file into two | jazz | High Level Programming | 2 | 10-20-2006 08:55 AM |
| dividing the screen >>> | ShockTeam | UNIX for Dummies Questions & Answers | 4 | 11-06-2001 08:29 PM |