If you are on a unix system...you can just say diff file1 file2.  On Windows
there is probably something comparable.
-----Original Message-----
From: Najamuddin, Junaid
To: [EMAIL PROTECTED]
Sent: 8/28/2001 9:18 AM
Subject: Formatting text

Hi,
Here is my script, I am comparing two txt files which are pipe delimited
line by line if they match then their is no output but if they do not
match then it gives an output about the difference 
My both files are loaded in the array and I am comparing line by line
How can I compare a value in a certain field within an array line by
line between two files so that I can have result I want 
instead of comparing whole line
The txt files are attached for your visual ease they are not pipe
delimited and the field names are displayed, In the script they will be
pipe delimited without any field name or header
If you can help me out
thanks
 
 
my($snapshot, $baseline);  # Defining txt files 
 
# First file
$snapshot = "./302-snap.txt"; # List of Svcs currently running loc at
c:\perl
 
# Second file
$baseline = "./302-base.txt";  # List of All Svcs which should be
running
 
my(@arr1, @arr2, @result);  # Defining arrays
my($fld1, $fld2, $fld3, $fld4); # Defining variables for fields
my($match, $cnt, $val1, $val2, $finalresult); # Defining scalar
variables
$match = "N"; 
 
#Open snapshot file and insert every line into @arr1
open(SNAPSHOT, $snapshot) or die "Unable to open $snapshot."; # Open the
txt file and place it in filehandle        
 
$cnt = 0;
while ( <SNAPSHOT> ) # Looping thru the filehandle snapshot
 {
 $arr1[$cnt] = $_;
 $cnt = $cnt + 1;
  } 
  close (SNAPSHOT); # close the filehandle snapshot
 
#Open baseline file and insert every line into @arr2
open(BASELINE, $baseline) or die "Unable to open $baseline."; # Open the
txt file and place it in filehandle     
 
$cnt = 0;
while ( <BASELINE> ) # Looping thru the filehandle baseline
{
 $arr2[$cnt] = $_;
 $cnt = $cnt + 1;
  } 
  close (BASELINE); # close filehandle baseline
 
# Outer loop is for baseline file
# Inner loop is for snapshot file
# Taking one element from @arr2 (baseline) and comparing it with all the
elements in @arr1(snapshot) and 
# If their is no match then insert that name into @result.
 
$cnt = 0;
foreach $val2 (@arr2) # referring to baseline
{
 foreach $val1 (@arr1) # referring to snapshot
 {
  if ($val1 eq $val2) 
  {
   $match = "Y";
  }
 }
 if  ($match eq "N") 
 {
  $result[$cnt] = $val2;
  $cnt = $cnt + 1;
 }
 
 $match = "N";
 }
 
$finalresult = 0; # initializing to zero
foreach $val1 (@result)
{
 $finalresult = $finalresult + 1;
}
 
if ($finalresult >  0 ) 
{
 print "\nList of SICK Siebel-Components \n\n"; # If some svc is not
functioning
 foreach $val1 (@result)
 {
  ($fld1,$fld2,$fld3,$fld4) =  split(/\|/,"$val1");# separating req
fields for output
  print "Svc-Component $fld4, of Siebel-Svc '$fld3'($fld2)\n";
  
 }
}
else
{
 print "\nAll Siebel-Components are Functioning Fine\n"; # When all svcs
are running fine
}

 
 <<302-base.txt>>  <<302-snap.txt>>  <<ATT3705189.txt>> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to