bash bc (standard_in) 1: parse error
A line in bash code:
average=$(echo "scale=4; $s/$i" | bc -l) s=42.91 and i=148,i expect to get average=0,2899.can you fix the error. Thanks in advance |
Tried it:
Code:
#!/bin/bash Code:
chmod +x avg.sh |
Actually the message i posted was just one line of my code.I thought,only that line was the reason of error.Now,i think something other than that line casues error.I'm sending the full code.
Note:The aim of this code is to analize output of unix sar command.I'm going to work on -c,-r and -u commands.I'm asked to find miminum,maximum and average of each column of sar output.I'm working on sar -c command now.I just want you to help me to find the average of "proc/s" column. The links: program: http://rapidshare.com/files/7243665/sar.sh input file is created from a .sa raw data file(sar -c -f ornek2.sa > ornek2-c.txt): http://rapidshare.com/files/7243666/ornek2-c.txt |
|
bash code: http://www.rafb.net/paste/results/8Zfn8P85.html
ignore the 3rd line of the code(that's how i generated the input file) input file(ornek2-c.txt): http://www.rafb.net/paste/results/xKMpYT30.html |
I'd say that this is really the sort of task which is much better accomplished using Perl:
Code:
#!/usr/bin/perl -w |
thank you for replying but i'm asked to do that job with bash
|
OK, some commends on your script:
...BUT shell is really not ideal for this sort of number crunching. Having to invoke an external program for every line of input will lead to woefully bad performance for larger input files. The shell is good for a lot of stuff, but really not this sort of thing. Perl or awk are more ideal and installed on most any unix-like OS you will encounter. I assume since bash was mandated this is a sort of homework (Hence me not posting a complete script). Get it working in bash, but tell them it is not ideal for this sort of tasks for the reasons I mentioned, and any more you can think of. You might even get extra marks. That or you'll be marked down for making the person who set the problem look silly. Ho hum. |
Quote:
|
All times are GMT -5. The time now is 08:58 AM. |