Prev: subtraction files
Next: copy files
From: Janis Papanagnou on 25 May 2010 06:43 I am looking for a regexp that matches the ANSI terminal escape sequences (ESC [ ...) (for xterm), or alternatively for a tool (Linux) that replaces ANSI terminal sequences by an arbitrary chosen fixed replacement. Thanks. Janis
From: Andrew McDermott on 25 May 2010 08:13 Janis Papanagnou wrote: > I am looking for a regexp that matches the ANSI terminal escape sequences > (ESC [ ...) (for xterm), or alternatively for a tool (Linux) that replaces > ANSI terminal sequences by an arbitrary chosen fixed replacement. Thanks. > > Janis Are these sequences "hardwired" into an application, or is the application using curses? If the latter, you should be able to fudge a terminfo entry to produce the required sequences. See terminfo(5). Andrew
From: pk on 25 May 2010 08:24 Janis Papanagnou wrote: > I am looking for a regexp that matches the ANSI terminal escape sequences > (ESC [ ...) (for xterm), or alternatively for a tool (Linux) that replaces > ANSI terminal sequences by an arbitrary chosen fixed replacement. Thanks. I've never done that, but I suppose any regex flavor that can match the escape character would do, so for example with GNU sed's ERE to match coloring sequences: \x1b\[[0-9]+;[0-9]+m or something similar. $ GREEN='\033[01;32m'; YELLOW='\033[01;33m' $ printf "$GREEN - $YELLOW\n" | sed -r 's/\x1b\[[0-9]+;[0-9]+m/FOO/g' FOO - FOO Apologies if I didn't understand correctly what you're after.
From: Janis Papanagnou on 25 May 2010 09:15 Andrew McDermott wrote: > Janis Papanagnou wrote: > >> I am looking for a regexp that matches the ANSI terminal escape sequences >> (ESC [ ...) (for xterm), or alternatively for a tool (Linux) that replaces >> ANSI terminal sequences by an arbitrary chosen fixed replacement. Thanks. > > Are these sequences "hardwired" into an application, or is the application > using curses? If the latter, you should be able to fudge a terminfo entry > to produce the required sequences. See terminfo(5). I am telnet'ing to a server that emits those ANSI sequences in addition to the data I am interested in. It's not specified what that server will actually emit, therefore I am looking for a "universal" regexp for those sequences. Probably something like \027[[]\([0-9]*;\)+[A-Za-z0-9] or so. Since it's likely that I might make mistakes when defining this, and since I believe that it's as well likely that someone else already invented that wheel, I am asking. Janis
From: Janis Papanagnou on 25 May 2010 09:19
pk wrote: > Janis Papanagnou wrote: > >> I am looking for a regexp that matches the ANSI terminal escape sequences >> (ESC [ ...) (for xterm), or alternatively for a tool (Linux) that replaces >> ANSI terminal sequences by an arbitrary chosen fixed replacement. Thanks. > > I've never done that, but I suppose any regex flavor that can match the > escape character would do, so for example with GNU sed's ERE to match > coloring sequences: > > \x1b\[[0-9]+;[0-9]+m > > or something similar. > > $ GREEN='\033[01;32m'; YELLOW='\033[01;33m' > $ printf "$GREEN - $YELLOW\n" | sed -r 's/\x1b\[[0-9]+;[0-9]+m/FOO/g' > FOO - FOO > > Apologies if I didn't understand correctly what you're after. Sorry for having been unclear. I know that I just need some BRE/ERE tool, like sed, to substitute the actual ANSI codes. I was interested in a regexp that covers all ANSI sequences in one regexp expression because, actually, I don't know what the telnet server will emit. (Please see also my response to Andrew.) Janis |