Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am working with the text of the 300 tang poems, which unfortunately is a single file containing both Chinese and English. Since I am interested in 'extracting' the English, I hope to use sed, grep,ortr to simply return all lines that contain Latin characters. So, for example, this text:


南山截竹為觱篥, 此樂本自龜茲出。 
流傳漢地曲轉奇, 涼州胡人為我吹; 
傍鄰聞者多歎息, 遠客思鄉皆淚垂。 
世人解聽不解賞, 長飆風中自來往。 
枯桑老柏寒颼飀, 九雛鳴鳳亂啾啾。 
龍吟虎嘯一時發, 萬籟百泉相與秋。 
忽然更作漁陽摻, 黃雲蕭條白日暗。 
變調如聞楊柳春, 上林繁花照眼新。 
歲夜高堂列明燭, 美酒一杯聲一曲。

Li Qi

Bamboo from the southern hills was used to make this pipe. 
And its music, that was introduced from Persia first of all, 
Has taken on new magic through later use in China. 
And now the Tartar from Liangzhou, blowing it for me, 
Drawing a sigh from whosoever hears it, 
Is bringing to a wanderer's eyes homesick tears.... 
Many like to listen; but few understand. 
To and fro at will there's a long wind flying, 
Dry mulberry-trees, old cypresses, trembling in its chill. 
There are nine baby phoenixes, outcrying one another; 
A dragon and a tiger spring up at the same moment; 
Then in a hundred waterfalls ten thousand songs of autumn 
Are suddenly changing to The Yuyang Lament; 
And when yellow clouds grow thin and the white sun darkens, 
They are changing still again to Spring in the Willow Trees. 
Like Imperial Garden flowers, brightening the eye with beauty, 
Are the high-hall candles we have lighted this cold night, 
And with every cup of wine goes another round of music.

I would like a command that returns only the line 051, skips the Chinese, then returns the line 'seven character ancient verse' and everything following.

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

Why not just:

# grep -e "[a-zA-Z0-9]\|^$" file.txt
share|improve this answer
that's exactly what i needed. thanks. –  ixtmixilix May 29 '11 at 13:06
Note that you cannot rely on [a-zA-Z0-9] doing what you expect -- those ranges are strictly locale-specific. –  Chris Down Feb 6 at 7:47
add comment

The following Perl command prints the lines that do not contain any Chinese character (Han script). -CIO tells perl that the input and output are encoded in UTF-8.

perl -CIO -lne '/\p{Han}/ or print'
share|improve this answer
wow., a Unicode Codeblock filter.. thanks for pointing that one out... (perl's) regex keeps coming up with more an more surprises (for me, at least)... That is definitely going to come in handy. –  Peter.O May 30 '11 at 3:30
very nice answer –  guido May 30 '11 at 8:37
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.