Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confuing issue with IF statement ... driving me mad! 1

Status
Not open for further replies.

RFC1795

IS-IT--Management
Feb 13, 2003
76
US
Hi All

I'm stuck on something and not sure what the problem is. This should be basic stuff but I'm not getting it to work.

All I want to do is run a small shell script against a file to test if the numbers match up. If they do, print PASS or if not FAIL.

The file I want to run against contains info like this:

Code:
2293595,2293595
2293596,2293596
2293597,2293597
2293598,2293598

No special characters that I can see and no whitespace on end etc.

The script:
Code:
for N in `cat $1 | awk -F, '{print $1}' `
 do
  N2=`cat $1 | grep "$N" | awk -F, '{print $2}'`
  ## This section added to try debug issue
  echo "$N" | wc
  echo "$N."
  echo "$N2" | wc
  echo "$N2."
 if [ "$N1" = "$N2" ]
  then
   echo "PASS"
  else
 echo " FAIL"
 fi
done

This is sample output from that when run against the file:

Code:
      1       1       8
2293595.
      1       1       9
.293595
 FAIL
      1       1       8
2293596.
      1       1       9
.293596
 FAIL
      1       1       8
2293597.
      1       1       9
.293597

So something is wrong on N2 .. its putting a value after the "." I'm using to test. It's also dropping a character.

Any ideas what the issue might be or a way around this?

Thanks in advance.
 
Never mind. Sorted it!! Ran dos2unix against my data file and that sorted everything. That's what happens when you use Windows - pah!
 
you mean Win-doze :-;
i am going to give you a star just for following up with the answer to your own problem ( so many don't bother) & highlighting an easily overlooked cause of trouble


I do not Have A.D.D. im just easily, Hey look a Squirrel!
 
Anyway, why not simply this ?
Code:
awk -F, '{sub(/\r$/,"");if($1!=$2){rc=1;exit}}END{print rc ? "FAIL" : "PASS"}' $1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
another thing you may want to check:

[tt]
for N in `cat $1 | awk -F, '{print $1}' `
# variable is called N
do
N2=`cat $1 | grep "$N" | awk -F, '{print $2}'`
## This section added to try debug issue
echo "$N" | wc
echo "$N."
echo "$N2" | wc
echo "$N2."
if [ "$N1" = "$N2" ]
# and here you use N1, which is never initialized ???
then
echo "PASS"
else
echo " FAIL"
fi
done
[/tt]

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top