Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to parse the output of a command that expects to be writing to the screen. It has data separated by move-to-origin control sequences (for the VT220, ESC[1;1H). I only need the last part (i.e. after the last move-to-origin).

I have tried doing this multiple ways (primarily awk and sed), but the problem is always that parts of the control sequence have special meaning (to the program, not just to the shell), and I cannot quote them when I substitute tput's output.

Any suggestions?


Here is an example of what I am looking to parse (ESC is the escape character):

Page 1; line 1
Page 1; line 2
ESC[1;1HPage 2; line 1
Page 2; line 2
ESC[1;1HPage 3; line 1
Page 3; line 2

I am looking to get the following, which is what would be on the terminal after the program has run.

Page 3; line 1
Page 3; line 2
share|improve this question
Could you give an example of the actual text you are trying to parse? – terdon Dec 8 '12 at 16:58
This sort of thing would be easiest to do in a scripting language. – dangph Dec 9 '12 at 5:39
I agree. My difficulty is in getting the control sequence into the script without the script trying to interpret it. – user130039 Dec 9 '12 at 15:17
@bugmenot, what platform are you on? I could knock out a script for you in Python or PowerShell in two minutes. – dangph Dec 9 '12 at 22:06
Which part do you not understand? Hopefully, this will clear it up: I am trying to get the last "page" of data, where a page is the last part after a control sequence. However, I cannot hard-code the control sequence because it can vary depending on the terminal on which it is run. I need to get it from tput, but when I do command substitution, the escape character is not properly quoted. – user130039 Dec 10 '12 at 0:40
up vote 0 down vote accepted

the easiest way to handle your problem:

  1. you convert all the control seq stuff by 'uuencode -m v' or 'xxd'
  2. now you can text process as usual by awk
  3. after all you back convert by 'uudecode -o -' or 'xxd -revert'

Alternatively use: bbe - a sed-like editor for binary files

if you need a more specific answer I need a more specific program sample

share|improve this answer
Thank you! That is beautifully simple. – user130039 Jan 5 '13 at 14:00
yeah, it's simple when you know where to search for it:-) I added a few things above... – sparkie Jan 5 '13 at 16:47

Your Answer


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