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-12-2009   #1 (permalink)
Shay Levy [MVP]


 
 

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

Hello Salah,

First, sorry for keeping you waiting!

Try to adjust the -syncWindow paremeter (bug in v1 that has already fixed
in CTP3), it should have a value of (the longest file content/2), this is
the results I get:

PS > diff (cat c:\v.txt) (cat c:\p.txt) -sync 105


InputObject SideIndicator
----------- -------------
Lexmark Optra E312L (MS) =>
Lexmark Optra M410 (MS) =>
Lexmark Optra S 1255 (MS) =>
Lexmark Optra T614 PS =>
Lexmark Optra W810 (MS) =>
Canon Bubble-Jet BJC-2000 <=
Canon Bubble-Jet BJC-240 <=
Canon Bubble-Jet BJC-3000 <=
Canon Bubble-Jet BJC-4300 <=
Canon Bubble-Jet BJC-85 <=
Canon Bubble-Jet S450 <=
Canon iR330-400 PS Ver 1.0 <=
Canon LBP-4i <=
Epson Stylus COLOR 400 ESC/P 2 <=
Epson Stylus COLOR 440 ESC/P 2 <=
Epson Stylus COLOR 760 ESC/P 2 <=
HP DeskJet 815C <=
HP DeskJet 840C/841C/842C/843C <=
hp deskjet 940c <=
HP LaserJet 4050 Series PCL <=
HP LaserJet 4050 Series PCL6 <=
HP LaserJet 4L/4ML PostScript <=
HP LaserJet 4ML <=
Konica 7040 Ver 2.02 <=
Lexmark E330 <=
Lexmark E332n <=
Lexmark 1020 Color Jetprinter <=
Lexmark Optra E310 PS <=
Lexmark Z52 Color Jetprinter <=
OKI C9600(PCL) <=
PDFCreator <=


Now you can filter on the SideIndicator property to get the values you want.


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


S> Hi Shay,
S>
S> here are the 2 examples files,
S> They contain the installed printer, V.txt for Vserver et P.txt for
S> the P
S> server.
S> I want to know which printers are not present in the other server
S> I've already tried to add the -replace option but I loose the
S> reference of the filename which indicate to me, where the printer is.
S>
S> .
S> "Shay Levy [MVP]" <no@xxxxxx> a ?crit dans le message de news:
S> 37162f6770a598cb6dfcd6b1aee2@xxxxxx...
Quote:
Quote:

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

>>>> 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
ignore whitespace when comparing files using compare-object? PowerShell
Re: 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