Jump to content

searching for a string in two files


Recommended Posts

I got two .txt files (like the one attached).

I make these files daily. So every file will be different. (500-2000 lines).

What i need is a function to start at top of file1.txt and see if it finds this line in file2.txt. And so on with all lines in file1.txt (not sorted). And if it finds a line that is in both file1.txt and file2.txt it shuld write it to a new file.

I could solve this by making a while inside a while sentence, but that wouldent be so effective.

This brings me to my question:

Can this be done effective (and relativly easy)

Any suggestions are welcome. =)

-Ols

liste.txt

Link to comment
Share on other sites

fileread both files.

you can do it a couple ways after that.

assume @crlf for breaks.

just off the top of my head, might have a bug in it.

$file1=Filereadall("file1.txt")
$file2=Filereadall("file2.txt")

$fileline1=stringsplit($file1,@crlf,1)
for $i=1 to $fileline1[0]
if stringinstr(@crlf & $file2 & @crlf,@crlf & $fileline1[$i] & @crlf) _
and $fileline1[$i]<>"" then filewrite("found.txt",$fileline1[$i] & @crlf)
next

func Filereadall($_file)
$_file=fileread($_file,filegetsize($_file))
return $_file
endfunc

edit added code for blank lines..

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

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...