I recently started processing Cyrillic text, and it's been really difficult.
I couldn't get my Python scripts to work with it at all. And I tried.
PHP worked well, but I don't know PHP. I just managed to hack a few things together, and I still don't feel comfortable in it. (It may become a bit of a mainstay, though, as it's proven unexpectedly useful.)
Of course, grep is out of the question.
Or is it?
That's what this question is about.
I wanted to do this:
alec@ROOROO:~/$ grep '\w\{4\}' cyrillicstuff
...and came up empty handed.
But is there a way I could have returned all words 4 characters or greater, given that they're all in Cyrillic, using good 'ol grep??
LANGset to something likeen_US.utf8. Howevergrepdoes not appear to be utf8 aware. An alternative would beperl -CDS -ne '/\w{4,}/ && print' cyrillicstuff. Not exactly short, but you could alias it or write a shell function to wrap it. – Patrick Jun 12 '12 at 2:24\w, so you can't use that, but have to use the named classes. – Jan Hudec Jun 12 '12 at 5:48grep -P '\w{4,}'fails to work, whileperl -CDS -ne '/\w{4,}/ && print'works just fine. In fact perl demonstrates the EXACT same behavior as grep when you dont give it the-CDSargument (which enables utf8 in perl). – Patrick Jun 12 '12 at 11:55\wdoes work (and is locale-aware) with GNU grep 2.6.3, but only with basic and extended regexps, not with-Pfor some reason. Perl doesn't import locale settings from the environment without-CLS. – Gilles Jun 12 '12 at 22:04\wdoesnt work (and even without-Pit didnt work here either). Though it does seem that the[[:alnum:]]solution below works, so ya, it was just the-Ptest that was failing :-) – Patrick Jun 13 '12 at 18:44