Home > Archive > AWK > October 2006 > esc sequences within strings
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
esc sequences within strings
|
|
| siegfried eckloff 2006-10-02, 9:56 pm |
| Hi,
This line of awk code:
print "\x1b --- \x1bA \x1bB \x1bC \x1bD \x1bE \x1bF --- \x1bG" > "dr-tmpname"
results in (displayed by elvis):
offset 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00000000 <1b>20 2d 2d 2d 20 ba 20 bb 20 bc 20 bd 20 be 20 . --- º » ? ? ?
00000010 bf 20 2d 2d 2d 20 1b 47 0a ¿ --- .G.
~
As you can see,
"\1b" yields ESC,
"\1bG" yields ESC G,
but
"\x1bA" to "\x1bF" result in hex 'ba' to hex 'bf',
NOT ESC A .. ESC F (as I expected). That puzzles me, as
I can't put ESC E into the file.
Would you please help me out?
thanks!
awk -W version shows:
GNU Awk 3.1.5
Copyright (C) 1989, 1991-2005 Free Software Foundation.
Regards siggi
--
s.e.
---
| |
| Bob Harris 2006-10-02, 9:56 pm |
| In article
<45219045$0$18490$9b4e6d93@newsspool3.arcor-online.net>,
siegfried eckloff <kobolomombo@tetumu.de> wrote:
> Hi,
>
> This line of awk code:
>
> print "\x1b --- \x1bA \x1bB \x1bC \x1bD \x1bE \x1bF --- \x1bG" > "dr-tmpname"
>
> results in (displayed by elvis):
>
> offset 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
> 00000000 <1b>20 2d 2d 2d 20 ba 20 bb 20 bc 20 bd 20 be 20 . --- º » ? ? ?
> 00000010 bf 20 2d 2d 2d 20 1b 47 0a ¿ --- .G.
> ~
>
> As you can see,
> "\1b" yields ESC,
> "\1bG" yields ESC G,
>
> but
>
> "\x1bA" to "\x1bF" result in hex 'ba' to hex 'bf',
> NOT ESC A .. ESC F (as I expected). That puzzles me, as
> I can't put ESC E into the file.
> Would you please help me out?
>
> thanks!
>
> awk -W version shows:
>
> GNU Awk 3.1.5
> Copyright (C) 1989, 1991-2005 Free Software Foundation.
>
>
> Regards siggi
looks like a bug to me.
As a workaround you could try
print "\x1b" "A \x1b" "B \x1b" "C \x1b" "D \x1b" "E \x1b" "F"
You could also try
esc = 27
printf("%cA %cB %cC %cD %cE %cF\n",
esc, esc, esc, esc, esc, esc)
You could also try
print "\033A \033B \033C \033D \033E \033F"
Bob Harris
| |
| siegfried eckloff 2006-10-03, 6:56 pm |
| Bob Harris wrote:
> In article
> <45219045$0$18490$9b4e6d93@newsspool3.arcor-online.net>,
> siegfried eckloff <kobolomombo@tetumu.de> wrote:
>
>
> looks like a bug to me.
such things happen...
> As a workaround you could try
>
> print "\x1b" "A \x1b" "B \x1b" "C \x1b" "D \x1b" "E \x1b" "F"
that doesn't work, too: there's an additional blank in between ESC and the letter:
print "\x1b", "E" > "dr-tmpname"
results in:
offset 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00000000 <1b>20 45 0a . E.
~
whereas both of these:
> You could also try
>
> esc = 27
> printf("%cA %cB %cC %cD %cE %cF\n",
> esc, esc, esc, esc, esc, esc)
>
> You could also try
>
> print "\033A \033B \033C \033D \033E \033F"
work well:
offset 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00000000 <1b>45 0a .E.
~
thank you!
siggi
--
s.e.
---
|
|
|
|
|