내가 작업 중인 텍스트당나라시 300편, 아쉽게도 중국어와 영어가 포함된 단일 파일입니다. 나는 영어를 "추출"하는 데 관심이 있으므로 라틴 문자가 포함된 모든 줄을 사용 sed, grep,
하거나 간단히 반환 하고 싶습니다 . tr
예를 들어 다음 텍스트는 다음과 같습니다.
051
七言古詩
李頎
聽安萬善吹觱篥歌
南山截竹為觱篥, 此樂本自龜茲出。
流傳漢地曲轉奇, 涼州胡人為我吹;
傍鄰聞者多歎息, 遠客思鄉皆淚垂。
世人解聽不解賞, 長飆風中自來往。
枯桑老柏寒颼飀, 九雛鳴鳳亂啾啾。
龍吟虎嘯一時發, 萬籟百泉相與秋。
忽然更作漁陽摻, 黃雲蕭條白日暗。
變調如聞楊柳春, 上林繁花照眼新。
歲夜高堂列明燭, 美酒一杯聲一曲。
Seven-character-ancient-verse
Li Qi
ON HEARING AN WANSHAN PLAY THE REED-PIPE
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.
나는 중국어를 건너뛰고 051행만 반환한 다음 "7자 고대 시" 행과 그 이후의 모든 항목을 반환하는 명령을 원합니다.
답변1
다음 Perl 명령은 중국어 문자가 포함되지 않은 행을 인쇄합니다(Han스크립트). -CIO
Perl에게 입력과 출력을 모두 UTF-8로 인코딩하도록 지시합니다.
perl -CIO -lne '/\p{Han}/ or print'
답변2
왜 안되나요:
# grep -e "[a-zA-Z0-9]\|^$" file.txt
답변3
주문하다
uconv -c -s -t ASCII <<\POEM
051
七言古詩
李頎
聽安萬善吹觱篥歌
南山截竹為觱篥, 此樂本自龜茲出。
流傳漢地曲轉奇, 涼州胡人為我吹;
傍鄰聞者多歎息, 遠客思鄉皆淚垂。
世人解聽不解賞, 長飆風中自來往。
枯桑老柏寒颼飀, 九雛鳴鳳亂啾啾。
龍吟虎嘯一時發, 萬籟百泉相與秋。
忽然更作漁陽摻, 黃雲蕭條白日暗。
變調如聞楊柳春, 上林繁花照眼新。
歲夜高堂列明燭, 美酒一杯聲一曲。
Seven-character-ancient-verse
Li Qi
ON HEARING AN WANSHAN PLAY THE REED-PIPE
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....
#END
POEM
산출
051
Seven-character-ancient-verse
Li Qi
ON HEARING AN WANSHAN PLAY THE REED-PIPE
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....