3 ms·
Some random thoughts: • Though the first pipeline is didactic, it can be done entirely within awk: awk ' BEGIN { l=0 } /purple/ { if(lengt
by js2 12y ago
Some random thoughts:
• Though the first pipeline is didactic, it can be done entirely within awk:
awk '
BEGIN { l=0 }
/purple/ {
if(length($1) >= l) { word = $1; l = length($1) }
}
END { print word }' < /usr/share/dict/words
• Named pipes are neat, but you can also use subshells and additional FDs (I am in no way arguing this is more clear):
(
(
(
echo out
echo err >&2
) | while read out; do echo "out: $out"; done >&3
) 2>&1 | while read err; do echo "err: $err"; done
) 3>&1
• Bash has "set -o pipefail" for cases where you want any process in the pipeline that exits non-zero to cause the entire pipeline to exit non-zero.