Unable to use grep to search logfiles output from Powershell scripts

I recently had to do some PowerShell work on a Windows server which outputted some log files for later review using the “Start-Transcript” function.

Later I went to review the logs looking for some specific information. I transferred them to my CentOS 5 Dev system to begin analyzing them with grep.

Every time I ran a grep command against the logs no results were returned. Very strange. Even if I used ‘cat’ first and then tried to grep that output grep would return no results.

Turns out the version of grep on CentOS 5 (GNU grep 2.6.3) does not support UTF-16 which is what my PowerShell logs were encoded in.

I ran the following command (thanks SuperUser) and converted all of my logs to UTF-8 and then grep began functioning properly again.

 

Leave a Reply

Your email address will not be published. Required fields are marked *