Hello, On Fri, 08 Jun 2012, Stefan Seyfried wrote:
Am 07.06.2012 08:28, schrieb David Haller:
On Tue, 29 May 2012, Stefan Seyfried wrote:
Am 29.05.2012 12:03, schrieb Guido Berhoerster:
Try mawk, it's an order of a magnitude faster than gawk and can be configured as /bin/awk using update-alternatives.
Yeah, and it has incompatible syntax. The following snippet to extract name and version from a debian control file does not work with mawk:
eval $(awk -F":[[:space:]*]" \ ^ are you sure the * belongs there?
no, but it works, should the * be behind the second ]?
I think so. If it's nside the outer '[]' the Field seperator is set to the regex "a ':', a space or a '*'". $ echo 'a:b: c: d:*e' | awk -F':[[:space:]*]' '{for(i=1;i<=NF;i++) { print $i; }}' a:b c d e If the '*' is out of the [], then the FS is set to the regex "a ':', any space (or none)". $ echo 'a:b: c: d:*e' | awk -F':[[:space:]]*' '{for(i=1;i<=NF;i++) { print $i; }}' a b c d *e Quite a difference, eh?
'/^Package:/{print "NAME=\""$2"\""}; /^Version:/{print "VERSION=\""$2"\""}' CONTROL/control)
'/^Package:/{printf("NAME=\"%s\"\n", $2);}; /^Version:/{printf("VERSION=\"%s\"\n", $2);}' CONTROL/control)
How does that help? $2 was empty. Guido explained this to me (in personal mail, as this topic is offtopic here), debian has an obsolet version of mawk which does not support character classed. The code is now using [\t ]* instead of [[:space:]*]
Then above should (have) definitely be(en) ':[[:space:]]*'. I think the "foo=\"%s\"\n", bar is easier to read. than "foo=\""bar"\"".
Usually, the "startup-penalty" of _any_ external tool outweighs by far a dozen lines of using var="${var/%foo/}" and similar lines.
and the readability penalty of
val="" while read a b c; do case $a in frob) val=$b; break ;; esac done < /foo/bar/baz
get_field_if() { f=$(( $1 - 1 )) while IFS="${4:-$IFS}" read -a line; do case ${line[$f]} in $2) echo "${line[ $3 ]}"; continue;; esac done } val=$(get_field_if 1 frob 2 < /foo/bar/baz) Sample: get_field_if 6 '*bash' 0 : < /etc/passwd outputs users having bash as shell, and would be in awk awk -F: '$7 ~ /.*bash$/ { print $1; }'
outweighs by far val=$(awk '/^frob /{ print $2 }' /foo/bar/baz)
I'd often write the whole script in awk if there's more than just one call to awk ;-P [..]
This benchmark is like most benchmarks: irrelevant.
It shows how much time the start of a (cached!) program takes in comparison to using shell-builtins. Nothing more, nothing less. Just keeping that fact in mind while scripting is good. Just as it's good to keep in mind that you should always quote your variables ;)
perl loads ~7 MB for doing nothing, awk loads "only" ~4 MB AFAICT. I *guess* (not tested) that as soon as you do anything useful, perl will load even more.
Only if you use extra Modules (not pragmas).
PS: for comparison this is a AMD Athlon II X2 250 with 2 * 3.0GHz cores.
CPU is mostly irrelevant for this kind of workload, it's I/O.
That was with warm caches, and it's hard to run a Suse without having bash, cut, grep, awk and perl in the disk-caches.
But this is still offtopic here. And the problem is solved now.
Fine. I'll bugger off then. -dnh -- If only I'd spent some of that effort on chasing girls. But then, it's much easier to understand a polysubstitution cypher than a female. -- Robert Uhl -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org