Jump to content

Searching For A String In Another File


Recommended Posts

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

Link to comment
Share on other sites

  • Developers

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)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...