format-hex
A
regular expression finds
new line (byte) characters (
0x0a
and
0x0d
); the replacement part embeds these characters into the escape secuences for
red and
reset:
format-hex xyz.txt |
out-string -stream |
foreach-object {
$line = $_
#
# Only apply coloring replacement on lines that don't start
# with a white spce;
#
if ($line -match '^\S') {
$line = $line -replace '(\b0[AD]\b)', "$([char]27)[38;5;9m`$1$([char]27)[0m"
}
$line
}
Result
In the result, the new line characters are now highlighted, which makes it easier, for example, to spot DOS or Unix line endings: