bc syntax error due to sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bc syntax error due to sed
# 1  
Old 03-25-2011
bc syntax error due to sed

Hi all,

before posting this questions i have looked up and found similar cases as the one i have but none of them had the answer i was lookink for.

i have the next two commands (with their corresponding output)

Code:
e1=$(grep KCAL input.OUT | sed 's/          FINAL HEAT OF FORMATION =        //g' | sed 's/ KCAL/0/g')
printf "%s\n" "Energia para configuracion 1= $e1 KCAL"
Energia para configuracion 1= -16.888990 KCAL

Code:
e2=$(grep KCAL input.OUT | sed 's/          FINAL HEAT OF FORMATION =        //g' | sed 's/ KCAL/0/g')
printf "%s\n" "Energia para configuracion 2= $e2 KCAL"
Energia para configuracion 2= -25.709240 KCAL

As you can see these two commands are correct, so $e1 and $e2 are actually numbers.

The problem is when i do the following:

Code:
scale="scale=6"
de=$(echo "$scale;$e2-$e1" | bc -l)
echo $de

i get the next error:

Code:
(standard_in) 1: syntax error

what i have found is that the sed output (or grep, certainly i'm not sure which of the two) is not compatible for a bc calculation; but i didn't find a solution for this. Perhaps the problem is not the one i think it should be.

Any suggestions would be apreciated. (Sorry for my english)
# 2  
Old 03-25-2011
Code:
de=$(echo "$scale;($e2)-($e1)" | bc -l)

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 03-25-2011
WOW, that was pretty simple!

Thank you very much!

---------- Post updated at 03:02 PM ---------- Previous update was at 03:02 PM ----------

WOW, that was pretty simple!

Thank you very much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need fix for rsync Error due to version mismatch

rsync --delay-updates -F --compress --archive --rsh='/usr/bin/ssh -t -a -x' /web/admin/Transfer/data/ user1@destserver1:/tmp/testf rsync version on sender server is:3.0.9 rsync version on sender server is:3.0.6 Linux sourceserver1 3.10.0-693.17.1.el7.x86_64 #1 SMP Sun Jan 14 10:36:03 EST... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Ssh failing due to Bad owner error

i am logged in with "user1" on host1. I m trying to ssh to host2 using user id "user2" $ ssh user2@host2 Bad owner or permissions on /home/user1/.ssh/config Question 1: Can you please tell me why am i getting the Bad owner permissions error on that directory ? Question 2: Where is it... (7 Replies)
Discussion started by: mohtashims
7 Replies

3. UNIX for Advanced & Expert Users

Error due to unset variable - Solaris vs GNU Linux - Help needed

Hi all, I have a weird problem. When i run the below code in SunOS and Linux i get different outputs ==== $ cat tst.ksh #!/bin/ksh echo "Abc" > $LOG_FILE echo "Ret - $?" ===== In Solaris $ ./tst.ksh Abc Ret - 0 In GNU Linux (1 Reply)
Discussion started by: NickKnight
1 Replies

4. Shell Programming and Scripting

sed syntax error

Hi, In the following excerpt of shell script code: I could not understand the sed syntax. Could anyone shed some light on this? configure_ssl() { jboss_conf_file=$1 echo "Configuring SSL for -" ${jboss_conf_file} isSSLSetup=`echo cat ${jboss_conf_file} | grep <Connector... (2 Replies)
Discussion started by: royalibrahim
2 Replies

5. Shell Programming and Scripting

"Syntax Error sometimes due to corruption of variable value "

Hi , I have script as follows , #!/usr/bin/ksh -x if then alias echo="echo -e" fi MAX_ENTRIES=1024 nb_of_entries=`echo "$list_of_entries" | wc -w` # Set number of tables eval nb_of_tables=\`expr `expr $nb_of_entries / $MAX_ENTRIES` + 1 \` # Output the number of tables echo... (6 Replies)
Discussion started by: breezevinay
6 Replies

6. Shell Programming and Scripting

Read/Search file being written to giving error due to timing issues

The following is a piece of code to rename LOG_FILE_NEW to LOG_FILE once you get a result (either RUNNING or SHUTDOWN) RESULT="" sleep 30 while ; do sleep 10 RESULT=`sed -n '/RUNNING/'p ${LOG_FILE_NEW}` if ; then RESULT=`sed -n '/SHUTTING_DOWN/'p ${LOG_FILE_NEW}` fi done mv... (3 Replies)
Discussion started by: sonorous
3 Replies

7. HP-UX

Pid X killed due to text modification or page I/O error

Hello everybody, I have a HP-UX B.11.11. I had one disk and added one new. When trying to configure the second disk Not Using the Logical Volume Manager(from SAM) I have this error: Pid X killed due to text modification or page I/O error I tryed to add another partion on the first disk,... (5 Replies)
Discussion started by: savus
5 Replies

8. Shell Programming and Scripting

sed error : Syntax error: redirection unexpected

My script is throwing the error 'Syntax error: redirection unexpected' My line of code.. cat nsstatustest.html | sed s/<tr><td align="left">/<tr><td align="left" bgcolor="#000000"><font color="white">/ > ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3 HTML tags are getting in the way but they're needed to... (3 Replies)
Discussion started by: phpfreak
3 Replies

9. Shell Programming and Scripting

aborted due to compilation error

I wanted to edit the time for a cron job that cleans out the quarantine in mailscanner. etc/cron.daily/clean.quarantine I edited the file #!/usr/bin/perl # # IMPORTANT NOTE: # # Change the next line to 0 instead of 1 to enable this script. # By default it will be disabled and... (2 Replies)
Discussion started by: mcraul
2 Replies

10. UNIX for Advanced & Expert Users

Problem due to Fork Error

Hi, I have developed a datastage job...which has many process running in parallel..but because of Fork Error my job is not working:( Can any body help me out to solve this Fork error problem.:rolleyes: My Os is SUNOS. IS there any setting in Unix through admin where in if i set some paramter... (8 Replies)
Discussion started by: Amey Joshi
8 Replies
Login or Register to Ask a Question