Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Re: ignore whitespace when comparing files using compare-object?

Reply
 
Old 03-08-2009   #1 (permalink)
Shay Levy [MVP]


 
 

Re: ignore whitespace when comparing files using compare-object?

Hello Salah,


$f1= (get-content v.txt) -replace " "
$f2=(get-content p.txt) -replace " "
....

Can you attach sample files and an example of the desired output?

---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar


S> HI,
S>
S> I currently use the following idea to compare to txt files,
S>
S> $f1=(get-content v.txt)
S>
S> $f2=(get-content p.txt)
S>
S> $total=$f2+$f1|group-object|where {$_.count -lt 2}
S>
S> you obtain diff between the two files,
S>
S> Count Name Group
S>
S> ----- ---- -----
S> 1 Lexmark Optra E312L (MS) {p.txt}
S> 1 Lexmark Optra M410 (MS) {p.txt}
S> 1 Lexmark Optra S 1255 (MS) {p.txt}
S> 1 Lexmark Optra T614 PS {p.txt}
S> 1 Lexmark Optra W810 (MS) {p.txt}
S> 1 Canon Bubble-Jet BJC-2000 {v.txt}
S> 1 Canon Bubble-Jet BJC-240 {v.txt}
S> 1 Canon Bubble-Jet BJC-3000 {v.txt}
S> 1 Canon Bubble-Jet BJC-4300 {v.txt}
S> 1 Canon Bubble-Jet BJC-85 {v.txt}
S> 1 Canon Bubble-Jet S450 {v.txt}
S> 1 Canon iR330-400 PS Ver... {v.txt}
S> where name is the line and group the filename, i've tried to remove
S> white
Quote:
Quote:

>> space by using -replace(" ",""), but I loose the group property. If
>> someone has a better soluce I'm very interesting by
>>
>> "bigdave64" <bigdave64@xxxxxx> a écrit dans le
>> message de news:
>> 251FD85B-0AB7-4DD2-BDF4-526ACBF2D475@xxxxxx...
>>
>> I was using compare-object recently to compare some text files. I
>> quickly discovered that there doesn't seem to be any way to tell
>> compare-object to ignore white space differences. Unfortunately,
>> this made compare-object almost useless to me, so I switched to
>> gnuwin32 diff, which is much more fully featured.
>>
>> Does anyone know whether compare-object will have more
>> options/features under PS 2.0, such as 'ignore whitespace' (-w switch
>> with gnuwin32 diff).
>>



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: ignore whitespace when comparing files using compare-object? PowerShell
ignore whitespace when comparing files using compare-object? PowerShell
Comparing files with compare-object PowerShell
Testing object arrays using Compare-Object and -contains PowerShell
Adding canonical aliases for Compare-Object, Measure-Object, New-Object PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46