PowerShell v2 Find Control Characters in Text File



Lets say you are trying to load a file (totally hypothetical) and your system (hypothetically again) yells at you.  Knowing folks (not any one in particular, but, those imaginary troublemakers out there) will occasionally forget to mention that control characters (anything in the hex range 0x00 - 0x17) might be in a file I needed to find a way to identify just which lines in a given file might be posing problems.  So, I can up with this:
PS > Get-Content C:someimaginaryfile.txt -ReadCount 1 | % { if($_ -match "[x00-x17]") {$_} }
If you are using regular expressions to format a range to examine, you will want to use the xdd syntax where dd is just a two character string representing the character you want to filter for. I was reminded of this tidbit here:
regex not matching certain characters
Since this never happens in the real world, hopefully this is for naught as it will have no effect on anyone out there in the ether.

Related Posts by Categories

0 comments:

Post a Comment