bug-gawk
[Top][All Lists]
Advanced

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

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


From: Steffen Nurpmeso
Subject: [bug-gawk] Interpretation of escape sequences in variable content
Date: Tue, 17 Nov 2015 18:25:14 +0100
User-agent: s-nail v14.8.5-145-g8facf61

Hello!

Long story: after switching my machine i regulary work with
  GNU/Linux again (first time since short after Debian Woody) and
  finally got frustrated about a dramatical performance impact that
  can be seen when running the configuration script of the MUA
  i maintain.  I found out that reading a file of 432 lines via
  redirected input via a loop like

    while read line; do
       line="`echo ${line} |\
             ${sed} -e '/^[         ]*#/d' -e '/^$/d' -e 's/[       ]*$//'`"
       [ -z "${line}" ] && continue

  took over 14 seconds in LC_ALL=C environment.  This is GNU sed.
  Now that frustration was finally big enough i've switched all that
  to awk(1) changing the look to

    while read line; do
       line=`${awk} -v LINE="${line}" 'BEGIN{
          gsub(/^[[:space:]]+/, "", LINE);\
          gsub(/[[:space:]]+$/, "", LINE);\
          if(index(LINE, "#") == 1)\
             LINE = "";\
          print LINE
       }'`
       [ -z "${line}" ] && continue

  That is faster.  :P  With nawk it once again is is >~40% percent
  faster, so i could half the time to 7.7 seconds for me.  (mawk is
  comparable.)

But now back to GNU awk :-).
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.

--steffen



reply via email to

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