Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams
grep -a "[^\x20-\x7e]+" test.csv
grep -a '[^\x20-\x7e]+' test.csv
grep "[^\x20-\x7e]+" test.csv
grep '[^\x20-\x7e]+' test.csv

also tried the flags -P and -E but all do not return me the result I want. In Powershell, I did

Select-String -Pattern '[^\x20-\x7E]+' test.csv

and it returned me the expected result.

Could someone point me in the right direction for MINGW64 bash grep (GNU grep) 3.1 on Windows10? It is installed via git download for windows here: https://git-scm.com/download/win

@WiktorStribiżew It doesn't for my environment. I get the entire file contents as my output. – ycx Apr 26, 2020 at 11:18 @WiktorStribiżew Its a standard Windows10 install and MINGW64 is installed via git download for Windows. – ycx Apr 26, 2020 at 11:26 Also, try grep -P "[^[:ascii:]]" if you need to print any line that has non-ASCII symbol. – Wiktor Stribiżew Apr 26, 2020 at 12:44

It appears the POSIX BRE and ERE syntax in grep for Windows do not support \xXX notation.

You may use -P option to enable the PCRE regex engine and then use

grep -P "[^\x{00}-\x{7E}]" file
grep -P "[^[:ascii:]]" file

to find any line containing a non-ASCII character.

NOTE that you cannot use [^\x20-\x7E] range because the CR (part of the line ending in Windows text files) will get matched, and all lines but the last (if it is not followed with trailing line break(s)) will get matched. You may add CR symbol though to the negated character class and use grep -P "[^\x{0D}\x{20}-\x{7E}]" file though.

Thanks for the answer, this works. However, I do have a requirement to use grep for this. :( – ycx Apr 26, 2020 at 11:40 On Windows10, the default is grep (GNU grep) 3.1 via MINGW64 and I'm actually interested in finding out why this does not work in this particular case if it could be helped. – ycx Apr 26, 2020 at 11:50

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.