I made a few assumptions .
I assumed you file looked something like
[tt][blue]
Info: me.abc 123
Info: you.txt 456
Total: 579
[/blue][/tt]
I also assumed that you wanted to compare a couple of numerical values
First - I think you script is failing becasue you are using == instead of =.
== Numerical comparision
= string comparison
[tt][blue]
(( a == b )) is a mathmatical expresion
equal to true when a & b are
integers AND they are equal.
(( a = b )) is a mathmatical expresion which
sets a equal to the value of b.
In KSH mathmatical expresions need
contained in (( )) or $(( ))
(( )) - boolean
(( 1 > 3 )) false
(( 1 < 2 )) true
$(( )) - kinda of command substition
x=$(( 5 + 3 )) x=8
[[ $a = $b ]] is a logical expresion which
evaluates to true if the strings
a and b are equal
[/blue][/tt]
In your script you use == instead of =.
Like I said I assumed your file was formated like the above. Which means the values you want to compare for the Info record are in the third field. So if you are doing a number compare then
[tt][green]
x=`awk '/Info: .*.abc/{print $3}' results.log`
y=`awk '/Info: .*.txt/{print $3}' results.log`
z=`awk '/Total: /{print $2}' results.log`
if (( x == z ));
then
echo "match" >> grep.txt
else
echo "does not match" >> grep.txt
fi
[/green][/tt]
"$" is not necessary inside (( ))
If you want to compare
STRING values
[tt][green]
x=`awk '/Info: .*.abc/{print $3}' results.log`
y=`awk '/Info: .*.txt/{print $3}' results.log`
z=`awk '/Total: /{print $2}' results.log`
if [[ $x = $z ]] ;
then
echo "match" >> grep.txt
else
echo "does not match" >> grep.txt
fi
[/green][/tt]
One more thing, it took me a while to figure out what the ; was used for , I usually left it off and it is not needed in your script, BUT...
Every Unix command produces a True or False, so for example lets say you wanted to echo a statement if you find the value FOOBAR in a file called my.txt
[tt][green]
if grep -q FOOBAR my.txt; then
echo "I found FOOBAR"
else
echo "I did not find FOOBAR"
fi
[/green][/tt]
JRjr
![[morning] [morning] [morning]](/data/assets/smilies/morning.gif)