2

with this problem I am beating my head with walls, please help.

I have two files Sheetthickness.k which contains a single value of initial thickness and minThick.k which contains the final thickness only a single number. I want to calculate the percentage decrease in thickness so I used.

fina="$(cat minThick.k)";
echo $fina
init="$(cat Sheetthickness.k)";
echo $init 

echo |awk "{ print ($init-$fina)/($init) }" > LSDynaResponse.txt

In shell where there is no other command and the files are already there then it works perfectly , but when the files are created by a software and then these commands are used, it gives error.

awk: { print (-)/() }  
awk:           ^ syntax error
awk: { print (-)/() }
awk:            ^ syntax error
awk: { print (-)/() }
awk:             ^ unterminated regexp

Any other elegant way to do this task?

hamad khan
  • 369
  • 1
  • 5
  • 14
  • 1
    @perreal: That is incorrect. You either need to use `echo` to give AWK something via `stdin` to consume or do the calculation in a `BEGIN` block. Otherwise it will hang waiting for intput. – Dennis Williamson Jul 16 '12 at 10:52

1 Answers1

1

It sounds like you have empty files or no files at all, try like this:

fina="$(cat minThick.k)"       || echo "No min file!!"
[[ -z $fina ]]                 && echo "Null min value!!"
echo $fina
init="$(cat Sheetthickness.k)" || echo "No init file!!"
[[ -z $init ]]                 && echo "Null init value!!"
echo $init
echo "($init-$fina)/($init)"   | bc -l > LSDynaResponse.txt
perreal
  • 94,503
  • 21
  • 155
  • 181