I have a single line file like this :
Average Fragmentation Quotient : 3.084121
Now I want to store the value which comes after ":" i,e 3.084121 into a variable.
And if this variable crosses above 6 i want to call another script...
can any one help me on this please ..
x=`awk '{print int($2)}' FS=: input_file`
if [ $x -gt 6 ]
then
<call your script here>
fi
Guru.
Hi Guru,
Thanks for the reply..
I want to make 3 more more updation like
1]f x is >0.6
2] less 7
3] less 0.8 ..
please suggest for same...
var=$(cat infile)
var2=${var##* }
-or-
read x x x x var2 < infile
end then:
if [ ${var2%%.*} -gt 6 ]; then
echo "do stuff with \$var2: $var2"
fi
In ksh93 you can just do this:
if [ $var2 -gt 6 ]; then
this dosent work for me ...
What doesn't work for you?
I am getting this error :
line 12: [: 0.6: integer expression expected
That is because only integer expressions can be use in test statements in any shell other than ksh93. Did you try earlier this suggestion?
if [ ${var2%%.*} -gt 6 ]; then
$ echo $var2
6.1
$ echo ${var2%%.*}
6
Otherwise you could use the utility bc ..