News for hackers. Stuff that matters.
Re:Pipes and Filters by js2 on Tuesday September 16, 2014 @04:36PM (#8326956)
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.

There are no comments on this comment yet.