Windows Vista Forums

Help
  1. #1


    Nik Guest

    Help

    I have two files "File1" and "File2". I think "File2" may contain some of
    the elements I have in "File1" I wish to compare these two files and extract
    the duplicate Items and put them into a new file. The furthest I have gotten
    is to compare the files and read the individual array items, but I can't
    seem to pull the duplicates. I know there are duplicates but still can't get
    them. all help appreciated. Thanks

    $File1 = @(Get-Content D:\File1.csv)
    $File2 = @(Get-Content D:\File2.csv)
    $duplicates =@()



    for ( $i=1; $i -le $file1.count; $i++ )
    {
    Write-Host $file1[$i]
    }

    for ( $j=1; $j -le $file1.count; $j++ )
    {
    Write-Host $file1[$j]
    }


    for ( $l=1; $l -le $file1.count; $l++ )
    {
    if ( $file1[$i] -eq $file2[$j] )
    {
    Write-Host "Match Found"

    }
    else
    {
    Write-host "Match Not found"
    }
    }



    Write-Host $file1[9]
    write-host $file2[3]
    $File1.Count
    $File2.Count


      My System SpecsSystem Spec

  2. #2


    Nik Guest

    Re: Help

    Ok, so I've gotten this and SOME duplicates, however, it is still NOT
    reading all the duplicates.

    $file1 = @(get-content d:\File1.csv) | sort
    $file2 = @(get-content d:\file2.csv) | sort
    compare-object $file2 $file1 -includeequal

    Can someone tell me why I may not be getting all the duplicates. I can see
    some of the duplicates are exactly the same in the files but the script does
    not pick them up
    Any suggestions




    "Nik" <nalleyne@newsgroup> wrote in message
    news:uYTdmyRpKHA.1548@newsgroup

    > I have two files "File1" and "File2". I think "File2" may contain some of
    > the elements I have in "File1" I wish to compare these two files and
    > extract the duplicate Items and put them into a new file. The furthest I
    > have gotten is to compare the files and read the individual array items,
    > but I can't seem to pull the duplicates. I know there are duplicates but
    > still can't get them. all help appreciated. Thanks
    >
    > $File1 = @(Get-Content D:\File1.csv)
    > $File2 = @(Get-Content D:\File2.csv)
    > $duplicates =@()
    >
    > for ( $i=1; $i -le $file1.count; $i++ )
    > {
    > Write-Host $file1[$i]
    > }
    >
    > for ( $j=1; $j -le $file1.count; $j++ )
    > {
    > Write-Host $file1[$j]
    > }
    >
    >
    > for ( $l=1; $l -le $file1.count; $l++ )
    > {
    > if ( $file1[$i] -eq $file2[$j] )
    > {
    > Write-Host "Match Found"
    >
    > }
    > else
    > {
    > Write-host "Match Not found"
    > }
    > }
    >
    >
    >
    > Write-Host $file1[9]
    > write-host $file2[3]
    > $File1.Count
    > $File2.Count

      My System SpecsSystem Spec

  3. #3


    stej Guest

    Re: Help

    Look at http://dmitrysotnikov.wordpress.com/...object-gotcha/
    It should solve your problem

    (shortly:
    RESOLUTION

    Explicitly set sync window to half of the size of the smaller
    collection. In our case, the collections have 15 elements, so sync
    window should be set to 7:

    Compare-Object $set1 $set2 -SyncWindow 7
    )

    On Feb 4, 5:41*am, "Nik" <nalle...@newsgroup> wrote:

    > Ok, so I've gotten this and SOME duplicates, however, it is still NOT
    > reading all the duplicates.
    >
    > $file1 = @(get-content d:\File1.csv) | sort
    > $file2 = @(get-content d:\file2.csv) | sort
    > compare-object $file2 $file1 *-includeequal
    >
    > Can someone tell me why I may not be getting all the duplicates. I can see
    > some of the duplicates are exactly the same in the files but the script does
    > not pick them up
    > Any suggestions
    >
    > "Nik" <nalle...@newsgroup> wrote in message
    >
    > news:uYTdmyRpKHA.1548@newsgroup
    >

    > > I have two files "File1" and "File2". I think "File2" may contain some of
    > > the elements I have in "File1" I wish to compare these two files and
    > > extract the duplicate Items and put them into a new file. The furthest I
    > > have gotten is to compare the files and read the individual array items,
    > > but I can't seem to pull the duplicates. I know there are duplicates but
    > > still can't get them. all help appreciated. Thanks
    >

    > > $File1 = @(Get-Content D:\File1.csv)
    > > $File2 = @(Get-Content D:\File2.csv)
    > > $duplicates =@()
    >

    > > for ( $i=1; $i -le $file1.count; $i++ )
    > > * *{
    > > * * * *Write-Host $file1[$i]
    > > * *}
    >

    > > for ( $j=1; $j -le $file1.count; $j++ )
    > > * *{
    > > * * * *Write-Host $file1[$j]
    > > * *}
    >

    > > for ( $l=1; $l -le $file1.count; $l++ )
    > > * *{
    > > * * * *if ( $file1[$i] -eq $file2[$j] )
    > > * * * * * *{
    > > * * * * * * * *Write-Host "Match Found"
    >

    > > * * * * * *}
    > > * * * * else
    > > * * * * * *{
    > > * * * * * * * *Write-host "Match Not found"
    > > * * * * * *}
    > > * *}
    >

    > > Write-Host $file1[9]
    > > write-host $file2[3]
    > > $File1.Count
    > > $File2.Count

      My System SpecsSystem Spec

  4. #4


    Nik Guest

    Re: Help

    Thanks your example works on another two files where I did the number
    example and a string example, but it does not work with the two files i
    need. I will try to regenerate the data.
    Thanks for your help at least I get the idea.

    "stej" <cerna.zelva@newsgroup> wrote in message
    news:93ba8560-2728-4e6e-9c59-47cd10123881@newsgroup

    > Look at
    > http://dmitrysotnikov.wordpress.com/...object-gotcha/
    > It should solve your problem
    >
    > (shortly:
    > RESOLUTION
    >
    > Explicitly set sync window to half of the size of the smaller
    > collection. In our case, the collections have 15 elements, so sync
    > window should be set to 7:
    >
    > Compare-Object $set1 $set2 -SyncWindow 7
    > )
    >
    > On Feb 4, 5:41 am, "Nik" <nalle...@newsgroup> wrote:

    >> Ok, so I've gotten this and SOME duplicates, however, it is still NOT
    >> reading all the duplicates.
    >>
    >> $file1 = @(get-content d:\File1.csv) | sort
    >> $file2 = @(get-content d:\file2.csv) | sort
    >> compare-object $file2 $file1 -includeequal
    >>
    >> Can someone tell me why I may not be getting all the duplicates. I can
    >> see
    >> some of the duplicates are exactly the same in the files but the script
    >> does
    >> not pick them up
    >> Any suggestions
    >>
    >> "Nik" <nalle...@newsgroup> wrote in message
    >>
    >> news:uYTdmyRpKHA.1548@newsgroup
    >>

    >> > I have two files "File1" and "File2". I think "File2" may contain some
    >> > of
    >> > the elements I have in "File1" I wish to compare these two files and
    >> > extract the duplicate Items and put them into a new file. The furthest
    >> > I
    >> > have gotten is to compare the files and read the individual array
    >> > items,
    >> > but I can't seem to pull the duplicates. I know there are duplicates
    >> > but
    >> > still can't get them. all help appreciated. Thanks
    >>

    >> > $File1 = @(Get-Content D:\File1.csv)
    >> > $File2 = @(Get-Content D:\File2.csv)
    >> > $duplicates =@()
    >>

    >> > for ( $i=1; $i -le $file1.count; $i++ )
    >> > {
    >> > Write-Host $file1[$i]
    >> > }
    >>

    >> > for ( $j=1; $j -le $file1.count; $j++ )
    >> > {
    >> > Write-Host $file1[$j]
    >> > }
    >>

    >> > for ( $l=1; $l -le $file1.count; $l++ )
    >> > {
    >> > if ( $file1[$i] -eq $file2[$j] )
    >> > {
    >> > Write-Host "Match Found"
    >>

    >> > }
    >> > else
    >> > {
    >> > Write-host "Match Not found"
    >> > }
    >> > }
    >>

    >> > Write-Host $file1[9]
    >> > write-host $file2[3]
    >> > $File1.Count
    >> > $File2.Count
    >

      My System SpecsSystem Spec

Help problems?