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 16:26:04 +0100
User-agent: s-nail v14.8.5-145-g8facf61

 |Aharon Robbins <address@hidden> wrote:
 ||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

Thanks again for such a response on a bug tracker.  You were not
only absolutely right but the resulting code only needs a second.
(I want to take this opportunity to remark that you will be
credited in the next release of my MUA already, because of the
messed up e-mail you've send to TUHS (remember, the one you've
resend and excused yourself for), it caused me to implement deeper
content inspection for *mime-counter-evidence*, back in September.)
Thanks!

--steffen

 |Date:   2015-11-18 16:00:20 +0100
 |
 |    [mk-conf-tweaks] mk-conf.sh: speed up config evaluation (Aharon Robbins)..
 |    
 |    after switching my machine for the first time since 2009 and
 |    starting to regulary work in VMs i have seen a dramatic
 |    performance breakdown in the
 |      Reading and preparing configuration from "make.rc"
 |    configuration step: evaluating the 432 line file via
 |    
 |      while read line; do
 |         # This should be [[:space:]] but needs -E; so test SPC/HT
 |         line="`echo ${line} |\
 |               ${sed} -e '/^[         ]*#/d' -e '/^$/d' -e 's/[       ]*$//'`"
 |         [ -z "${line}" ] && continue
 |    
 |    required
 |    
 |      real    0m14.697s
 |      user    0m4.290s
 |      sys     0m9.483s
 |    
 |    so i've switched to a version that uses awk instead of sed and
 |    that was faster (~13.7 with gawk, ~8.8 with nawk).  However
 |    causing a faulty bug report of mine to the GNU awk bug ML due to
 |    
 |      gawk: warning: escape sequence `\$' treated as plain `$'
 |    
 |    caused by
 |    
 |      while read line; do
 |        line=`${awk} -v LINE="${line}" 'BEGIN{
 |    
 |    Aharon Robbins responded
 |    
 |      Gawk is better than nawk and mawk. :-)  The warning became permanent
 |      when I myself used a bad escape sequence[.]
 |    
 |    and he is of course not only right
 |    
 |      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
 |    
 |    but also suggested to switch completely to awk; the loop was
 |    converted to the form as above to allow newline backslash-escaping
 |    and follow-up lines, which can also be implemented in awk with
 |    minimal effort, so i've done it, and the result, with GNU awk:
 |    
 |      Reading and preparing configuration from "./make.rc" ...
 |      real    0m1.083s
 |      user    0m0.307s
 |      sys     0m0.710s
 |      done

 |+< ${rc} ${awk} 'BEGIN{line = ""}{\
 |+   gsub(/^[[:space:]]+/, "", $0);\
 |+   gsub(/[[:space:]]+$/, "", $0);\
 |+   if(gsub(/\\$/, "", $0)){\
 |+      line = line $0;\
 |+      next;\
 |+   }else\
 |+      line = line $0;\
 |+   if(index(line, "#") == 1){\
 |+      line = "";\
 |+   }else if(length(line)){\
 |+      print line;\
 |+      line = "";\
 |+   }\
 |+}' |
 | while read line; do



reply via email to

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