2016-12-25 5 views
3

Il est vérifié que [\u4e00-\u9fff] peut correspondre à des caractères chinois dans vim.Comment faire correspondre les caractères chinois avec grep?

:%g/[\u4e00-\u9fff]/d 

La commande ci-dessus peut supprimer toutes les lignes contenant des caractères chinois.

ls /tmp/test 
ktop 1_001.png.bak 
fonts.dir.bak 
New 
Screenshot from 2016-09-12 16:50:29.png.bak 
你好 

Maintenant, je veux extraire les fichiers dont le nom est des caractères chinois.

ls /tmp/test |grep -P '[\x4e\x00-\x9f\xff]' 

La commande ne peut pas obtenir les fichiers dont le nom est des caractères chinois.
Comment le réparer?

ls/tmp/test | grep -v '[a-z]' peut l'obtenir, mais c'est ce que je veux.

+2

Essayez ce 'ls/tmp/test | grep -P "[一 - 龥]" '. –

Répondre

5

Pour correspondre à peu lignes (noms) qui ont Han (chinois) caractères, vous pouvez utiliser [\p{Han}]:

ls /tmp/test | grep -P '[\p{Han}]' 

\p{Han} est parmi the Unicode-script category properties usable in any PCRE-supporting engine:

\p{Common} \p{Arabic} \p{Armenian} \p{Bengali} \p{Bopomofo} 
\p{Braille} \p{Buhid} \p{Canadian_Aboriginal} \p{Cherokee} 
\p{Cyrillic} \p{Devanagari} \p{Ethiopic} \p{Georgian} \p{Greek} 
\p{Gujarati} \p{Gurmukhi} \p{Han} \p{Hangul} \p{Hanunoo} \p{Hebrew} 
\p{Hiragana} \p{Inherited} \p{Kannada} \p{Katakana} \p{Khmer} \p{Lao} 
\p{Latin} \p{Limbu} \p{Malayalam} \p{Mongolian} \p{Myanmar} \p{Ogham} 
\p{Oriya} \p{Runic} \p{Sinhala} \p{Syriac} \p{Tagalog} \p{Tagbanwa} 
\p{TaiLe} \p{Tamil} \p{Telugu} \p{Thaana} \p{Thai} \p{Tibetan}