Sign in to follow this  
Followers 0
Sleiman

Searching For A String In Another File

6 posts in this topic

I have 2 files. One contains a 6 characters employee number. The second file contains a information about the employee.

What I need is a way to find out if for each employee number, if there is a hit in the second file. End result would be:

Emp# Hit

123456 Y

123457 N

123458 Y

I need to loop through the employee file and for each record, search the second file for the occurance of employee number.

Looking forward for some ideas,

Seiman

Share this post


Link to post
Share on other sites



And what is the problem?

Share this post


Link to post
Share on other sites

I am looking for a script sample on how to do it!

Share this post


Link to post
Share on other sites

here you have an example that does more or less what you want...

You still need to have a look at the match test ...

$FILE1 = "lookup.txt"
$FILE2 = "emprec.txt"
$FILE3 = "match.txt"
$FH2=FileOpen("emprec.txt",0)
If $FH2 = -1 Then
   MsgBox(0, "Error", "Unable to open:"& $FILE2)
   Exit
EndIf
While 1
   $LINE2 = FileReadLine($FH2)
   If @error = -1 Then ExitLoop
   $FH1=FileOpen($FILE1,0)
   If $FH1 = -1 Then
      MsgBox(0, "Error", "Unable to open :" & $FILE1)
      Exit
   EndIf
   While 1
      $LINE1 = FileReadLine($FH1)
      If @error = -1 Then 
         FileWriteLine($FILE3,$LINE2 & " N") 
         ExitLoop
      EndIf
     ; put here your match test
      If StringMid($LINE1,4,10) = $LINE2 Then
         FileWriteLine($FILE3,$LINE2 & " Y") 
         ExitLoop
      EndIf
   Wend
   FileClose($FH1)   
Wend
FileClose($FH2)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I have 2 files.  One contains a 6 characters employee number.  The second file contains a information about the employee.

What I need is a way to find out if for each employee number, if there is a hit in the second file.  End result would be:

Emp#      Hit

123456    Y

123457    N

123458    Y

I need to loop through the employee file and for each record, search the second file for the occurance of employee number.

Looking forward for some ideas,

Seiman

H'mmn, how big are the files? How big are they ever likely to be?

If they are small enough to load at once, the compairison processing c/would be different from reading a line at a time, and MUCH faster.

Gene


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

Thank you MassSpammer, your recommendation work very well.

Sleiman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0