3

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

sevenever
  • 773
  • 1
  • 8
  • 14

2 Answers2

0

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.

harithski
  • 666
  • 1
  • 6
  • 18
  • printing is not enough, as the escape sequences are still in the output (even if they're hidden): For example, I'd like to search for a string in a terminal log and only search for strings actually displayed, eg: `$script terminal_log.txt >>logging to terminal_log.txt $echo barfoo >>foo $cat terminal_log.txt|grep bar|wc -l >>1` I expected 0 instead of 1 since bar was deleted. (sorry for formatting, but stackoverflow doesn't allow line breaks in comments) – timotheecour Feb 26 '14 at 22:03
0

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.

Edd Steel
  • 719
  • 4
  • 16
  • cleaning with sed won't work as the terminal sequence may be quite complex, such as clearing screen, backspace etc. – timotheecour Feb 26 '14 at 21:25
  • That's what od is for. clear screen or backspace will come out of od as `\f`, `\b` or `FF`, `BS` depending on the option. I was only suggesting sed for formatting `od`'s output. – Edd Steel Feb 28 '14 at 01:40
  • I don't want to just remove special control sequences, I want to interpret them (see all use cases). – timotheecour Feb 28 '14 at 03:08