Last active
June 21, 2017 14:01
-
-
Save dajare/a610ee6ed10784cce972fc977cd0f095 to your computer and use it in GitHub Desktop.
Counts unicode range (total printable characters) in mixed text file; currently set to Hebrew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding: utf-8 | |
import re | |
import codecs | |
import sys | |
## chmod 0755 to make executable | |
## run with `./name.py input_file` | |
## source: https://unix.stackexchange.com/a/372270/99759 | |
find_hebrew = re.compile(ur'[\u0590-\u05ff]+') # python 2 | |
# find_hebrew = re.compile(r'[\u0590-\u05ff]+') # python 3 | |
text_file = sys.argv[1] | |
count = 0 | |
with codecs.open(text_file, 'rU', encoding='utf-8') as f: | |
for line in f.readlines(): | |
for n in find_hebrew.findall(line): | |
count += len(n) | |
print(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HT: @stephenrauch
https://unix.stackexchange.com/a/372270/99759