0

I'm developing a pre-commit hook to avoid committing files with non-ascii chars, it works as well from unix system, using the below REGEX:

grep -P -n '[\x80-\xFF]' /tmp/app.txt

Now the issue that is giving me a lot of pain is that when i commit from windows, the result of the grep change, giving me a lot of char more than non ascii chars...

Does someone know how to fix this? I really try a lot of different things..

ivoruJavaBoy
  • 1,307
  • 2
  • 19
  • 39

1 Answers1

0

strings -n 1 filename will show the normal characters, but what if you only want to see the kind of file? file filename will show the kind of file but I am afraid it won't work for you.
You might try something like

cat /tmp/app.txt | tr -d "[:print:]\r\n" | wc -c

or avoiding the cat

tr -d "[:print:]\r\n" < /tmp/app.txt | wc -c
Walter A
  • 19,067
  • 2
  • 23
  • 43