0

I use grep to search for patterns which is working properly. However, when I redirect the output to any file, the output gets corrupted due to the encoding.

Is there a way to make the bash in windows output the file in normal UTF-8 encoding so normal text editors can read it properly?

EDIT: It looks like this when I redirect output the grep results to any file:

[35m[KFile.txt[m[K[36m[K:[m[K[01;31m

I'm running latest Windows and I have bash installed by using developer mode and enabling the bash.

The output gets messed up in the process. Even Windows version of linux text editors display the weird output. However, if I run cat on the file containing the weird output. It shows the output just fine with no issues.

I'm using Notepad++ to view the results.

Thanks

  • 2
    How does it look? What did you use? Did you check what encoding it's currently using? What are "normal text editors" in your opinion? What Windows version are you running and how are you running bash on it? – Seth Oct 20 '17 at 11:29
  • @Seth I edited the main post, please look at it – Cows42 Oct 20 '17 at 11:40
  • These are colour escape sequences, which shouldn't be enabled when grep output is redirected (and aren't for me). You can force their suppression by preceding grep with env LS_COLORS= . – AFH Oct 20 '17 at 11:53
  • A better way to suppress colours is to add --color=never to the grep run string. Somehow I missed it in the man page on Windows WSL, though it's there, and I've used it elsewhere. – AFH Oct 20 '17 at 12:56
1

That's not an encoding issue. The program whose output you are capturing is emitting ANSI control codes to set cursor position, foreground colour etc.

When you use cat the control codes are processed by the tty and so don't appear in raw form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.