开发者

VIM: deleting non-roman characters

开发者 https://www.devze.com 2023-02-14 08:29 出处:网络
I\'m working with a document with both Roman and Asian characters, an开发者_JS百科d I want put them each of them alone in two separated files and keeps their original structure, is it possible?

I'm working with a document with both Roman and Asian characters, an开发者_JS百科d I want put them each of them alone in two separated files and keeps their original structure, is it possible?

Thanks


Might be easier in Python. Here's a script that reads a text file and creates two output files: one with low-ASCII and one with everything else. If you have Python support compiled in Vim, the following should also be usable from within Vim (with minimal changes).

import codecs

mixedInput = codecs.open('mixed.txt', 'r', 'utf-8')
lowAsciiOutput = codecs.open('lowAscii.txt', 'w', 'utf-8')
otherOutput = codecs.open('other.txt', 'w', 'utf-8')

for rawline in mixedInput:
    line = rawline.rstrip()
    for c in line:
        if ord(c) < 2**7:
            lowAsciiOutput.write(c)
        else:
            otherOutput.write(c)
    otherOutput.write('\n')
    lowAsciiOutput.write('\n')

mixedInput.close()
lowAsciiOutput.close()
otherOutput.close()

example input file (mixed.txt):

欢迎来到Mifos管理区域

Does that do what you want?

Also saved as a gist: https://gist.github.com/855545

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号