Sign in to follow this  
Followers 0
Ace08

Counting values with mo match

4 posts in this topic

Hi guys

I know its just an easy problem but i realy cant figure it out, the idea would be having 2 sets of files one of these file will be a reference while the other will be the input, what im supposed to do here is to count the lines from file1 thats not existing in file 2 and those existing.

What i did was open both files, read a line from file1 and checks the lines from file2 if its not existing then it will be counted in the sample below the count for those non existing should only be equal to 2 since "train" and "sub" is not defined from file2

Thanks for the help

File1:

toy

boat

plane

van

train

sub

File2:

toy

boat

van

plane

$var = FileOpenDialog ("Choose The File.", @ScriptDir & "\Input", "File(*.txt)" , 2)
Local $file = FileOpen($var, 0), $count, $_count
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
While 1
 Local $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
 Local $RefFile = FileOpen(@ScriptDir & "\Input\b.txt",0)
 If $RefFile = -1 Then
  MsgBox(0, "Error", "Unable to open reference file.")
  Exit
 EndIf
 While 2
  $refFileLine = FileReadLine($RefFile)
  If @error = -1 Then ExitLoop
  If $line = $refFileLine Then
   $count = $count + 1
  Else
   $_count = $_count + 1
  EndIf
 WEnd
 FileClose($RefFile)
WEnd
FileClose($file)
MsgBox(0,"Notice", "Total match : " & $count & @CRLF & "Count no match : " & $_count)

Work smarter not harder.My First Posted Script: DataBase

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <Array.au3>

$File1 = _
"toy" & @LF & _
"boat" & @LF & _
"plane" & @LF & _
"van" & @LF & _
"train" & @LF & _
"sub"
$File1_Array = StringRegExp($File1, '(?m)([^\r\n]+)(?:[\r\n]+|$)', 3)
;~ _ArrayDisplay( $File1_Array )

$File2 = _
"toy" & @CRLF & _
"boat" & @CRLF & _
"van" & @LF & _
"plane"
$File2_Array = StringRegExp($File2, '(?m)([^\r\n]+)(?:[\r\n]+|$)', 3)
For $i = 0 To UBound( $File2_Array ) -1
ConsoleWrite ( $File2_Array[ $i ] )
Next

;Exit
;we have the data of each line
;Lets equate and if they are equal delete them
Local $aCommon[1], $aUnique[1], $iBound = UBound( $File2_Array ) -1
For $i = 0 To UBound( $File1_Array ) -1
For $n = 0 To $iBound
If $File2_Array[$n] = $File1_Array[$i] Then
_ArrayAdd ( $aCommon, $File1_Array[$i] )
ContinueLoop 2
ElseIf $n = $iBound Then
_ArrayAdd( $aUnique, $File1_Array[$i] )
EndIf
Next
Next
;Remove the first blank value
_ArrayDelete( $aCommon, 0 )
_ArrayDelete( $aUnique, 0 )
;Display the results :)
_ArrayDisplay( $aCommon, 'Common Strings' )
_ArrayDisplay( $aUnique, 'Unique Strings' )
Thumbs up if it helped ;) Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Wow, awesome PhoenixXL, you're one of the master of RegEx :thumbsup:

Share this post


Link to post
Share on other sites

Ace08,

what im supposed to do here is

Is this a class assignment?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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