ok this is probably going to turn out to be something really stupid but i've tried to use the following command in a script but the output is just a blank screen and i have to use Ctrl c to exit it.
awk 'BEGIN {printf "%.2f\n", '${bashArray[$count]}'>='$Variable' {print '${bashArray[$count]}'}}'
the command is it compare the values stored in an array to a variable and if the value in the array is greater than the variable to print the value of that array element.
if anyone could suggest why it doesn't work that'd be brill
You can't give the result of the print command to printf, try this:
awk 'BEGIN {printf("%.2f\n", '${bashArray[$count]}'>='$Variable'?'${bashArray[$count]}':"")}'
This should always print a line, even if the condition is false.
To avoid that you can do something like:
awk 'BEGIN {if('${bashArray[$count]}'>='$Variable')printf "%.2f\n",'${bashArray[$count]}'}'
1 Like
the second one sort of worked but it won't let me compare floating numbers. which is what i was trying to get it to do.
---------- Post updated at 09:15 PM ---------- Previous update was at 08:22 PM ----------
don't worry just tried the first one and it does what i want, thanks