issue in calculation

Hi all

Already posted this question,i belive i didn't exactly said my question.

I have data files it stored in the different path like
/st/vr/sum.dat
/st/vr/pass.dat
/st/vr/fail.dat

we are not suppoe to mention the hardcode value of the path.

I need to calculate the percentage of pass and fail.

so in my shell script i wrote like

total=$datafile/sum.dat
pass=$datafile/pass.dat
fail=$datafile/fail.dat

i tried in this way:
exp1=$SCR_DIR/$equal_count.dat/$EQUAL_COUNT*100
echo $exp1 | bc

and created an awk script : percentage.awk
{
printf ("%3.2f%%\n", $2/$1 * 100)
exit
}

like this and called through the shell script like

awk -f percentage.awk -v $total -v $pass > pass_percentage.dat

this is also not worked.

if the echo stament is fail to fetch the address of the exp1 and it's not calculating the percentage.

please advice me on this.

Can anybody advice me where am doing mistake?

Please post a samples of input files and required output.

Hi

This is my script am getting the data from the one CSV file and am taking the count of pass and fail records
and i need to find the percentage of the pass and fail respectively.

#!/bin/ksh
file1=/st/vr/count.csv
pass=/st/vr/pass.dat
fail=/st/vr/fail.dat
total=/st/vr/total_count.dat
equal_percentage=/st/vr/equal_percentage.dat
not_equal_percentage=/st/vr/not_equal_percentage.dat

#ToTAL record count
wc $file1 | awk '{print $1}' >> $total

#chking the count of pass records

grep -cw "pass" $file1 >> $pass

#chking the count of fail records

grep -cw "fail" $file1 >> $fail

#Chk the Eqaul percentage.
equal_percentage=`echo |awk '{print $a / 100 * $b}' a=/st/vr/pass.dat b=/st/vr/total_count.dat`

> pass=25
> fail=19
> total=44
> echo `echo $pass*100/$total | bc`% passed
56% passed
> echo `echo $fail*100/$total | bc`% failed
43% failed

Hi

I already tried in this way it's not working ,

echo `echo $pass*100/$total | bc`% passed

am getting error like Syntax at line 1

b'ze if my pass parameter hold the direct hot code values this statmt will work.

Am holding the pass value ,it again holds the /st/vr/pass.dat.

in this point only it's failing.that's the issue.
hope you understand my problem.
please let me know,if u need more information to help me out.

provide me some other solution to over some this issue.

So your $pass holds the filename location for a file.
That file contains one piece of information: the number of pass'es.

Why not redirect your pass calculation to a variable?
num_pass=$(grep -cw "pass" $file1)
and so on... then what I proposed earlier would work.

However you want to move the numbers to two files; I think your script is already doing this.

> cat passf
37
> cat totalf
64

Now I am setting variables that point to the file locations; again, I think your script is doing something like this already.

> passv="./passf"
> totalv="./totalf"

Showing that I can read the text behind the filenames stored inside the variables.

> echo `cat $passv` *100 / `cat $totalv`     
37 *100 / 64

Finally, showing math being done on those numbers.

> echo `cat $passv` *100 / `cat $totalv` | bc
57

okay,i belive this should work.
thanks for the solution.
am not able to connect to my network now and i'll check it tommorow and let you if i have any issues.

thank you for both of you guys !!

I'll let you know once i solved this issue.

hi thank you guys.

My problem got solved as per your proposed solutions. :):smiley: