Hi, I'm looking for some lib or tool to render text with escape squence chars in a text file. I dont know how to call this, but here is a example:
~$ echo -e "abc\vdef"
abc
def
~$
~$ echo -e "abc\vdef" > /tmp/xxxxx
~$ vi /tmp/xxxxx
I got abc^Kdef on screen.
so i'm searching some tool that can do开发者_如何学编程 this for me:
~$ sometool /tmp/xxxxx > /tmp/yyyyy
~$ vi /tmp/yyyyy
I can get
abc
def
in vi window.
\v is just a example, I need convert \v, \b, \f, etc.
to harithski: but what I want is:
$~/:sometool /tmp/xxxxx > /tmp/yyyyy
in python
>>> f=open('/tmp/yyyyyy').readlines()
>>> f[0]
>>> ['abc\n def']
which has three space between \n and def
the character \v in shell is represented differently in each editor/tool. If you do a cat of the file, you still get what you need
$ cat /tmp/xxxxx
abc
def
$
If you open the same file in python, you will see the character as \x0b. But when you print it, it is fine.
>>> f=open('/tmp/se').readlines()
>>> f[0]
['abc\x0bdef\n']
>>> print f[0]
abc
def
Basically it is a matter of representation. If your requirement is to read the file using a program or tool, the representation shouldn't be a problem.
Don't think I'm entirely understanding the question, but is od
going to help?
Example:
$ echo -e "abc\vdef" > temp $ cat temp abcdef $ od -c temp 0000000 a b c \v d e f \n 0000010
You could pipe that output through sed if you wanted to clean it up. Like I said, I'm not sure that's what you're asking.
精彩评论