

Tips for writing efficient Bash scripts - quoderat
http://hacktux.com/bash/script/efficient

======
hernan7
This stuff is good to know -- I have found the "sed -e" trick and doing
pattern matching inside awk help cut down on typing quite a bit. They may even
make the script more readable, once you become familiar with these idioms.

On the other hand, I don't know if these type of performance optimizations
will have many real-world applications. For example, if you are calling grep
and awk inside a loop, and find it unacceptable slow, I don't think you are
going to see a big performance gain by calling only awk. At that point, your
best bet may be to write that part of your script in Perl (or C, like I did
once back in the times before Perl was mainstream).

------
greg
Is it just me or do most of these seem like premature optimization? I would
rather use one command for filtering lines (grep) and another for filtering
columns (awk) than try to do both at once.

~~~
jkmcf
I generally take the definition of "premature optimization" to be "going out
of your way to improve performance". If you know a faster (better?) way, use
it. Sometimes, people seem to confuse YAGNI and premature optimization with
just "knowing better".

For your grep example, unless you are using the output of grep for something
else, there's no reason not to use the awk version except ignorance (which I'm
plenty guilty of re: awk and sed...)

