bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Interpretation of escape sequences in variable content


From: Steffen Nurpmeso
Subject: Re: [bug-gawk] Interpretation of escape sequences in variable content
Date: Wed, 18 Nov 2015 13:59:45 +0100
User-agent: s-nail v14.8.5-145-g8facf61

Hello.

Aharon Robbins <address@hidden> wrote:
 |> Date: Tue, 17 Nov 2015 18:25:14 +0100
 |> From: Steffen Nurpmeso <address@hidden>

 |> Long story: after switching my machine i regulary work with

..a bit too long..

 |>   i maintain.  I found out that reading a file of 432 lines via

 |>   took over 14 seconds in LC_ALL=C environment.  This is GNU sed.
 |
 |Something's really wrong.

Yes!  Unrelated to GNU awk?  (The empty loop takes ~1/4 second.)

 |> The problem manifests in a message like
 |>
 |>   gawk: warning: escape sequence `\$' treated as plain `$'
 |>
 |> that happens to happen if LINE a.k.a. ${line} looks like
 |>
 |>   #@ To embed a shell variable unexpanded, use two: "XY=\${HOME}".
 |>
 |> This however also happens with --traditional, and i think that
 |> should not happen, that seems to be a bug.  And neither nawk nor
 |> mawk complain.
 |
 |Gawk is better than nawk and mawk. :-)  The warning became permanent

The comparison is indeed pretty unfair.

  address@hidden (line='yo\$u'; gawk -v tv="$line" 'BEGIN{print tv}')
  gawk: warning: escape sequence `\$' treated as plain `$'
  yo$u
  address@hidden (line='yo\$u'; mawk -v tv="$line" 'BEGIN{print tv}')
  yo\$u
  address@hidden (line='yo\$u'; nawk -v tv="$line" 'BEGIN{print tv}')
  yo$u

You are absolutely right apart from this.

 |when I myself used a bad escape sequence.
 |
 |The warning isn't going to go away, although perhaps (perhaps!) it is
 |a minor bug to issue it for command line assignments.

If you ask, the error message can indeed be improved, though

  gawk: cmd. line:1: warning: escape sequence `\$' treated as plain `$'

for a variable assignment inside awk also doesn't say where and
what exactly happens.  I didn't know what happened until i traced
the lines read from the input file.

 |You have a few options.
 |
 |1. Switch to nawk or mawk

Honestly the test is now nawk->mawk->awk.  (Being a chaotic person
that uses an old-style vim / make / cc environment i cannot wait
over 13 seconds -- it may adversely affect the desire to never
need napkins in my conscious live.)

 |2. Use awk '...' 2> /dev/null to throw the warning away

That is what i've done.  (Of course that is a lobotomic approach.)

 |3. Recommended: Let awk parse the whole file for you instead of using
 |the shell to read it one line at a time. That should speed up the

And that is what i have to end up with and am heading for.
(read(1) to allow line-continuation with backslash-escaped
newlines.)

 |HTH,

Yes.  Oh, sorry for the noise.  And thanks for the answer.
Ciao!! ..from Germany

--steffen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]