Moderators: Eric, Tomas, robin, Michael
{ MergeAdrFiles - Version 1.00
{ Author: Scott Taylor - February 24, 2006
{
{ Purpose: Merge two spam IP address files into a single file. Can also be used to eliminate
{ duplicates from a single file by starting with File2.txt as either empty or non-existant.
{
{ Method: The script copies the IP addresses from File1.txt to File2.txt adding only addresses
{ not already contained in File2.txt. When finished the script reports the number of lines in
{ File1.txt and File2.txt at the start and File2.txt when complete. File1.txt remains unaltered.
{
{ Notes:
{ 1) File within a filter and LocateLine seem to have trouble with content on line 0.
{ As a result this script expects line 0, the first line, to be blank. Handling this apparent
{ bug complicates the script slightly around the InsertBlank section.
{ 2) My 2.5GHz Pentium 4 took over 30 seconds starting with File1.txt having 3450 addresses with
{ File2.txt empty or non-existant. In other words, this script can take a while. Be patient.
Set $FileName1 "..\File1.txt"
OpenBody $AdrList1 $FileName1
LineCount #AdrCnt1 $AdrList1 { get a starting count
Set $FileName2 "..\File2.txt"
AppendToFile False { always overwrite with AdrList2
OpenBody $AdrList2 $FileName2 { get existing list if any
LineCount #AdrCnt2 $AdrList2 { get a starting count
If #AdrCnt2 < 1 Then InsertBlank
GetLine $a 0 $AdrList2 { get line 0
CharCount #n $a { see if line 0 is blank
If #n < 2 Then NoBlank
:InsertBlank
InsertLine $AdrList2 0 "" { insert a blank line
:NoBlank
:SearchLoop
LineCount #n $AdrList1 { see if there are any addresses left
If #n < 2 Then Done
GetLine $Adr 1 $AdrList1 { get the first address from file1 (source file)
DeleteLine $AdrList1 1 1 { delete the first line (from the copy in memory only)
LocateLine #z $Adr $AdrList2 { search for IP address in destination file
If #z > 0 Then SearchLoop { if found don't add this adr to destination file
AppendBody $AdrList2 $Adr { add this address to destination file
GoTo SearchLoop
:Done
LineCount #AdrCnt3 $AdrList2 { get address count of merged files
Set $msg "File1.txt started with "
AddStrings $msg #AdrCnt1
Set $a "File2.txt started with "
AddStrings $a #AdrCnt2
AppendBody $msg "\n" { don't know why this is needed here ...
AppendBody $msg $a
Set $a "File2.txt ended with "
AddStrings $a #AdrCnt3
AppendBody $msg $a
MessageBox $msg
SaveBody $AdrList2 $FileName2 { save the merged result
EXIT
Return to PocoScript Help and How-To
Users browsing this forum: No registered users and 1 guest