(standard_in) 1: syntax error when using bc












0














I have written an .awk which executes some operation on a .tr file and writes the output to a file. The END section of .awk file prints this:



printf("%15.2fn%15.5fn%15.2fn%15.2fn%15.2fn%10.2fn%10.2fn%10.5fn", rThroughput, rAverageDelay, nSentPackets, nReceivedPackets, nDropPackets, rPacketDeliveryRatio, rPacketDropRatio,rTime) ;

printf("%15.5fn%15.5fn%15.5fn%15.5fn%15.0fn%15.9fn", total_energy_consumption, avg_energy_per_bit, avg_energy_per_byte, avg_energy_per_packet, total_retransmit,rEnergyEfficiency);


I call this .awk file from a .shfile. After executing the command which runs the .awk file, I iterate over the values generated by the .awk file.



        awk -f Wireless_udp.awk 802_11.tr > "TEMP"

while read val
do
l=$(($l + 1))

if [ "$l" == "1" ]; then
thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc)
# echo -ne "throughput: $val "
elif [ "$l" == "2" ]; then
del=$(echo "scale=5; $del+$val/$iteration_float" | bc)
# echo -ne "delay: $val "
elif [ "$l" == "3" ]; then
s_packet=$(echo "scale=5; $s_packet+$val/$iteration_float" | bc)
# echo -ne "send packet: $val "
elif [ "$l" == "4" ]; then
r_packet=$(echo "scale=5; $r_packet+$val/$iteration_float" | bc)
# echo -ne "received packet: $val "
elif [ "$l" == "5" ]; then
d_packet=$(echo "scale=5; $d_packet+$val/$iteration_float" | bc)
# echo -ne ;"drop packet: $val "
elif [ "$l" == "6" ]; then
del_ratio=$(echo "scale=5; $del_ratio+$val/$iteration_float" | bc)
# echo -ne "delivery ratio: $val "
elif [ "$l" == "7" ]; then
dr_ratio=$(echo "scale=5; $dr_ratio+$val/$iteration_float" | bc)
# echo -ne "drop ratio: $val "
elif [ "$l" == "8" ]; then
time=$(echo "scale=5; $time+$val/$iteration_float" | bc)
# echo -ne "time: $val "
elif [ "$l" == "9" ]; then
t_energy=$(echo "scale=5; $t_energy+$val/$iteration_float" | bc)
# echo -ne "total_energy: $val "
elif [ "$l" == "10" ]; then
energy_bit=$(echo "scale=5; $energy_bit+$val/$iteration_float" | bc)
# echo -ne "energy_bit: $val "
elif [ "$l" == "11" ]; then
energy_byte=$(echo "scale=5; $energy_byte+$val/$iteration_float" | bc)
# echo -ne "energy_byte: $val "
elif [ "$l" == "12" ]; then
energy_packet=$(echo "scale=5; $energy_packet+$val/$iteration_float" | bc)
# echo -ne "energy_packet: $val "
elif [ "$l" == "13" ]; then
total_retransmit=$(echo "scale=5; $total_retransmit+$val/$iteration_float" | bc)
# echo -ne "total_retrnsmit: $val n"
elif [ "$l" == "14" ]; then
energy_efficiency=$(echo "scale=9; $energy_efficiency+$val/$iteration_float" | bc)
# echo -ne "energy_efficiency: "
fi
# echo "$val"
done < "TEMP"


Everything was running fine, but when I added the last if-else condition and executed the script, it gave a (standard_in) 1: syntax error



Specifically, I'm taking about this segment of code:



            elif [ "$l" == "14" ]; then
energy_efficiency=$(echo "scale=9; $energy_efficiency+$val/$iteration_float" | bc)
# echo -ne "energy_efficiency: "


TEMP file contains:



      197645.74
0.32776
25000.00
7350.00
17348.00
29.40
69.39
24.99826
720.13300
0.00015
0.00117
0.09798
0
0.001166018


I'm having difficulty why it's giving an error. Any help would be appreciated.



Link to full code:



.tcl file which generates the .tr file
.awk file:
.sh file:



bash --version gives:



GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>


OS: Ubuntu 16.04 LTS










share|improve this question






















  • Is the variable energy_efficiency initialized anywhere? if not, the first time through the loop will have an empty value before the +
    – steeldriver
    22 mins ago










  • Yes, turns out I forgot to initialize the variable. @steeldriver
    – Robur_131
    17 mins ago










  • You can give an answer. I will be happy to accept it.
    – Robur_131
    16 mins ago
















0














I have written an .awk which executes some operation on a .tr file and writes the output to a file. The END section of .awk file prints this:



printf("%15.2fn%15.5fn%15.2fn%15.2fn%15.2fn%10.2fn%10.2fn%10.5fn", rThroughput, rAverageDelay, nSentPackets, nReceivedPackets, nDropPackets, rPacketDeliveryRatio, rPacketDropRatio,rTime) ;

printf("%15.5fn%15.5fn%15.5fn%15.5fn%15.0fn%15.9fn", total_energy_consumption, avg_energy_per_bit, avg_energy_per_byte, avg_energy_per_packet, total_retransmit,rEnergyEfficiency);


I call this .awk file from a .shfile. After executing the command which runs the .awk file, I iterate over the values generated by the .awk file.



        awk -f Wireless_udp.awk 802_11.tr > "TEMP"

while read val
do
l=$(($l + 1))

if [ "$l" == "1" ]; then
thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc)
# echo -ne "throughput: $val "
elif [ "$l" == "2" ]; then
del=$(echo "scale=5; $del+$val/$iteration_float" | bc)
# echo -ne "delay: $val "
elif [ "$l" == "3" ]; then
s_packet=$(echo "scale=5; $s_packet+$val/$iteration_float" | bc)
# echo -ne "send packet: $val "
elif [ "$l" == "4" ]; then
r_packet=$(echo "scale=5; $r_packet+$val/$iteration_float" | bc)
# echo -ne "received packet: $val "
elif [ "$l" == "5" ]; then
d_packet=$(echo "scale=5; $d_packet+$val/$iteration_float" | bc)
# echo -ne ;"drop packet: $val "
elif [ "$l" == "6" ]; then
del_ratio=$(echo "scale=5; $del_ratio+$val/$iteration_float" | bc)
# echo -ne "delivery ratio: $val "
elif [ "$l" == "7" ]; then
dr_ratio=$(echo "scale=5; $dr_ratio+$val/$iteration_float" | bc)
# echo -ne "drop ratio: $val "
elif [ "$l" == "8" ]; then
time=$(echo "scale=5; $time+$val/$iteration_float" | bc)
# echo -ne "time: $val "
elif [ "$l" == "9" ]; then
t_energy=$(echo "scale=5; $t_energy+$val/$iteration_float" | bc)
# echo -ne "total_energy: $val "
elif [ "$l" == "10" ]; then
energy_bit=$(echo "scale=5; $energy_bit+$val/$iteration_float" | bc)
# echo -ne "energy_bit: $val "
elif [ "$l" == "11" ]; then
energy_byte=$(echo "scale=5; $energy_byte+$val/$iteration_float" | bc)
# echo -ne "energy_byte: $val "
elif [ "$l" == "12" ]; then
energy_packet=$(echo "scale=5; $energy_packet+$val/$iteration_float" | bc)
# echo -ne "energy_packet: $val "
elif [ "$l" == "13" ]; then
total_retransmit=$(echo "scale=5; $total_retransmit+$val/$iteration_float" | bc)
# echo -ne "total_retrnsmit: $val n"
elif [ "$l" == "14" ]; then
energy_efficiency=$(echo "scale=9; $energy_efficiency+$val/$iteration_float" | bc)
# echo -ne "energy_efficiency: "
fi
# echo "$val"
done < "TEMP"


Everything was running fine, but when I added the last if-else condition and executed the script, it gave a (standard_in) 1: syntax error



Specifically, I'm taking about this segment of code:



            elif [ "$l" == "14" ]; then
energy_efficiency=$(echo "scale=9; $energy_efficiency+$val/$iteration_float" | bc)
# echo -ne "energy_efficiency: "


TEMP file contains:



      197645.74
0.32776
25000.00
7350.00
17348.00
29.40
69.39
24.99826
720.13300
0.00015
0.00117
0.09798
0
0.001166018


I'm having difficulty why it's giving an error. Any help would be appreciated.



Link to full code:



.tcl file which generates the .tr file
.awk file:
.sh file:



bash --version gives:



GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>


OS: Ubuntu 16.04 LTS










share|improve this question






















  • Is the variable energy_efficiency initialized anywhere? if not, the first time through the loop will have an empty value before the +
    – steeldriver
    22 mins ago










  • Yes, turns out I forgot to initialize the variable. @steeldriver
    – Robur_131
    17 mins ago










  • You can give an answer. I will be happy to accept it.
    – Robur_131
    16 mins ago














0












0








0







I have written an .awk which executes some operation on a .tr file and writes the output to a file. The END section of .awk file prints this:



printf("%15.2fn%15.5fn%15.2fn%15.2fn%15.2fn%10.2fn%10.2fn%10.5fn", rThroughput, rAverageDelay, nSentPackets, nReceivedPackets, nDropPackets, rPacketDeliveryRatio, rPacketDropRatio,rTime) ;

printf("%15.5fn%15.5fn%15.5fn%15.5fn%15.0fn%15.9fn", total_energy_consumption, avg_energy_per_bit, avg_energy_per_byte, avg_energy_per_packet, total_retransmit,rEnergyEfficiency);


I call this .awk file from a .shfile. After executing the command which runs the .awk file, I iterate over the values generated by the .awk file.



        awk -f Wireless_udp.awk 802_11.tr > "TEMP"

while read val
do
l=$(($l + 1))

if [ "$l" == "1" ]; then
thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc)
# echo -ne "throughput: $val "
elif [ "$l" == "2" ]; then
del=$(echo "scale=5; $del+$val/$iteration_float" | bc)
# echo -ne "delay: $val "
elif [ "$l" == "3" ]; then
s_packet=$(echo "scale=5; $s_packet+$val/$iteration_float" | bc)
# echo -ne "send packet: $val "
elif [ "$l" == "4" ]; then
r_packet=$(echo "scale=5; $r_packet+$val/$iteration_float" | bc)
# echo -ne "received packet: $val "
elif [ "$l" == "5" ]; then
d_packet=$(echo "scale=5; $d_packet+$val/$iteration_float" | bc)
# echo -ne ;"drop packet: $val "
elif [ "$l" == "6" ]; then
del_ratio=$(echo "scale=5; $del_ratio+$val/$iteration_float" | bc)
# echo -ne "delivery ratio: $val "
elif [ "$l" == "7" ]; then
dr_ratio=$(echo "scale=5; $dr_ratio+$val/$iteration_float" | bc)
# echo -ne "drop ratio: $val "
elif [ "$l" == "8" ]; then
time=$(echo "scale=5; $time+$val/$iteration_float" | bc)
# echo -ne "time: $val "
elif [ "$l" == "9" ]; then
t_energy=$(echo "scale=5; $t_energy+$val/$iteration_float" | bc)
# echo -ne "total_energy: $val "
elif [ "$l" == "10" ]; then
energy_bit=$(echo "scale=5; $energy_bit+$val/$iteration_float" | bc)
# echo -ne "energy_bit: $val "
elif [ "$l" == "11" ]; then
energy_byte=$(echo "scale=5; $energy_byte+$val/$iteration_float" | bc)
# echo -ne "energy_byte: $val "
elif [ "$l" == "12" ]; then
energy_packet=$(echo "scale=5; $energy_packet+$val/$iteration_float" | bc)
# echo -ne "energy_packet: $val "
elif [ "$l" == "13" ]; then
total_retransmit=$(echo "scale=5; $total_retransmit+$val/$iteration_float" | bc)
# echo -ne "total_retrnsmit: $val n"
elif [ "$l" == "14" ]; then
energy_efficiency=$(echo "scale=9; $energy_efficiency+$val/$iteration_float" | bc)
# echo -ne "energy_efficiency: "
fi
# echo "$val"
done < "TEMP"


Everything was running fine, but when I added the last if-else condition and executed the script, it gave a (standard_in) 1: syntax error



Specifically, I'm taking about this segment of code:



            elif [ "$l" == "14" ]; then
energy_efficiency=$(echo "scale=9; $energy_efficiency+$val/$iteration_float" | bc)
# echo -ne "energy_efficiency: "


TEMP file contains:



      197645.74
0.32776
25000.00
7350.00
17348.00
29.40
69.39
24.99826
720.13300
0.00015
0.00117
0.09798
0
0.001166018


I'm having difficulty why it's giving an error. Any help would be appreciated.



Link to full code:



.tcl file which generates the .tr file
.awk file:
.sh file:



bash --version gives:



GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>


OS: Ubuntu 16.04 LTS










share|improve this question













I have written an .awk which executes some operation on a .tr file and writes the output to a file. The END section of .awk file prints this:



printf("%15.2fn%15.5fn%15.2fn%15.2fn%15.2fn%10.2fn%10.2fn%10.5fn", rThroughput, rAverageDelay, nSentPackets, nReceivedPackets, nDropPackets, rPacketDeliveryRatio, rPacketDropRatio,rTime) ;

printf("%15.5fn%15.5fn%15.5fn%15.5fn%15.0fn%15.9fn", total_energy_consumption, avg_energy_per_bit, avg_energy_per_byte, avg_energy_per_packet, total_retransmit,rEnergyEfficiency);


I call this .awk file from a .shfile. After executing the command which runs the .awk file, I iterate over the values generated by the .awk file.



        awk -f Wireless_udp.awk 802_11.tr > "TEMP"

while read val
do
l=$(($l + 1))

if [ "$l" == "1" ]; then
thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc)
# echo -ne "throughput: $val "
elif [ "$l" == "2" ]; then
del=$(echo "scale=5; $del+$val/$iteration_float" | bc)
# echo -ne "delay: $val "
elif [ "$l" == "3" ]; then
s_packet=$(echo "scale=5; $s_packet+$val/$iteration_float" | bc)
# echo -ne "send packet: $val "
elif [ "$l" == "4" ]; then
r_packet=$(echo "scale=5; $r_packet+$val/$iteration_float" | bc)
# echo -ne "received packet: $val "
elif [ "$l" == "5" ]; then
d_packet=$(echo "scale=5; $d_packet+$val/$iteration_float" | bc)
# echo -ne ;"drop packet: $val "
elif [ "$l" == "6" ]; then
del_ratio=$(echo "scale=5; $del_ratio+$val/$iteration_float" | bc)
# echo -ne "delivery ratio: $val "
elif [ "$l" == "7" ]; then
dr_ratio=$(echo "scale=5; $dr_ratio+$val/$iteration_float" | bc)
# echo -ne "drop ratio: $val "
elif [ "$l" == "8" ]; then
time=$(echo "scale=5; $time+$val/$iteration_float" | bc)
# echo -ne "time: $val "
elif [ "$l" == "9" ]; then
t_energy=$(echo "scale=5; $t_energy+$val/$iteration_float" | bc)
# echo -ne "total_energy: $val "
elif [ "$l" == "10" ]; then
energy_bit=$(echo "scale=5; $energy_bit+$val/$iteration_float" | bc)
# echo -ne "energy_bit: $val "
elif [ "$l" == "11" ]; then
energy_byte=$(echo "scale=5; $energy_byte+$val/$iteration_float" | bc)
# echo -ne "energy_byte: $val "
elif [ "$l" == "12" ]; then
energy_packet=$(echo "scale=5; $energy_packet+$val/$iteration_float" | bc)
# echo -ne "energy_packet: $val "
elif [ "$l" == "13" ]; then
total_retransmit=$(echo "scale=5; $total_retransmit+$val/$iteration_float" | bc)
# echo -ne "total_retrnsmit: $val n"
elif [ "$l" == "14" ]; then
energy_efficiency=$(echo "scale=9; $energy_efficiency+$val/$iteration_float" | bc)
# echo -ne "energy_efficiency: "
fi
# echo "$val"
done < "TEMP"


Everything was running fine, but when I added the last if-else condition and executed the script, it gave a (standard_in) 1: syntax error



Specifically, I'm taking about this segment of code:



            elif [ "$l" == "14" ]; then
energy_efficiency=$(echo "scale=9; $energy_efficiency+$val/$iteration_float" | bc)
# echo -ne "energy_efficiency: "


TEMP file contains:



      197645.74
0.32776
25000.00
7350.00
17348.00
29.40
69.39
24.99826
720.13300
0.00015
0.00117
0.09798
0
0.001166018


I'm having difficulty why it's giving an error. Any help would be appreciated.



Link to full code:



.tcl file which generates the .tr file
.awk file:
.sh file:



bash --version gives:



GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>


OS: Ubuntu 16.04 LTS







bc






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 33 mins ago









Robur_131

124




124












  • Is the variable energy_efficiency initialized anywhere? if not, the first time through the loop will have an empty value before the +
    – steeldriver
    22 mins ago










  • Yes, turns out I forgot to initialize the variable. @steeldriver
    – Robur_131
    17 mins ago










  • You can give an answer. I will be happy to accept it.
    – Robur_131
    16 mins ago


















  • Is the variable energy_efficiency initialized anywhere? if not, the first time through the loop will have an empty value before the +
    – steeldriver
    22 mins ago










  • Yes, turns out I forgot to initialize the variable. @steeldriver
    – Robur_131
    17 mins ago










  • You can give an answer. I will be happy to accept it.
    – Robur_131
    16 mins ago
















Is the variable energy_efficiency initialized anywhere? if not, the first time through the loop will have an empty value before the +
– steeldriver
22 mins ago




Is the variable energy_efficiency initialized anywhere? if not, the first time through the loop will have an empty value before the +
– steeldriver
22 mins ago












Yes, turns out I forgot to initialize the variable. @steeldriver
– Robur_131
17 mins ago




Yes, turns out I forgot to initialize the variable. @steeldriver
– Robur_131
17 mins ago












You can give an answer. I will be happy to accept it.
– Robur_131
16 mins ago




You can give an answer. I will be happy to accept it.
– Robur_131
16 mins ago










1 Answer
1






active

oldest

votes


















0














Your script doesn't appear to initialize the variable energy_efficiency, so the first time around the loop



echo "scale=9; $energy_efficiency+$val/$iteration_float"


produces



scale=9; +197645.74/1.0


which is a syntax error (bc apparently allows unary -, but not unary +)



$ echo "scale=9; +197645.74/1.0" | bc
(standard_in) 1: syntax error




share





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492609%2fstandard-in-1-syntax-error-when-using-bc%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your script doesn't appear to initialize the variable energy_efficiency, so the first time around the loop



    echo "scale=9; $energy_efficiency+$val/$iteration_float"


    produces



    scale=9; +197645.74/1.0


    which is a syntax error (bc apparently allows unary -, but not unary +)



    $ echo "scale=9; +197645.74/1.0" | bc
    (standard_in) 1: syntax error




    share


























      0














      Your script doesn't appear to initialize the variable energy_efficiency, so the first time around the loop



      echo "scale=9; $energy_efficiency+$val/$iteration_float"


      produces



      scale=9; +197645.74/1.0


      which is a syntax error (bc apparently allows unary -, but not unary +)



      $ echo "scale=9; +197645.74/1.0" | bc
      (standard_in) 1: syntax error




      share
























        0












        0








        0






        Your script doesn't appear to initialize the variable energy_efficiency, so the first time around the loop



        echo "scale=9; $energy_efficiency+$val/$iteration_float"


        produces



        scale=9; +197645.74/1.0


        which is a syntax error (bc apparently allows unary -, but not unary +)



        $ echo "scale=9; +197645.74/1.0" | bc
        (standard_in) 1: syntax error




        share












        Your script doesn't appear to initialize the variable energy_efficiency, so the first time around the loop



        echo "scale=9; $energy_efficiency+$val/$iteration_float"


        produces



        scale=9; +197645.74/1.0


        which is a syntax error (bc apparently allows unary -, but not unary +)



        $ echo "scale=9; +197645.74/1.0" | bc
        (standard_in) 1: syntax error





        share











        share


        share










        answered 7 mins ago









        steeldriver

        34.5k35083




        34.5k35083






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492609%2fstandard-in-1-syntax-error-when-using-bc%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Entries order in /etc/network/interfaces

            新発田市

            Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)