Shell Tool Integration
Sort and Unique
Pick a Pipeline
Pipelines let one tool feed another. This example compares a unique sorted list with a reverse sorted list.
Program
Play the script to choose the pipeline mode and see the modeled output.
sort_unique_plan.sh
Replay: real traced execution (multi-file project)
#!/usr/bin/env bash
mode="unique"
input="beta alpha alpha"
if [ "$mode" = "unique" ]; then
command="sort | uniq"
output="alpha beta"
else
command="sort -r"
output="beta alpha alpha"
fi
echo "$command -> $output"
#!/usr/bin/env bash
mode="reverse"
input="beta alpha alpha"
if [ "$mode" = "unique" ]; then
command="sort | uniq"
output="alpha beta"
else
command="sort -r"
output="beta alpha alpha"
fi
echo "$command -> $output"
mode ← unique
3mode="unique"4input="beta alpha alpha"values this stepuniquemodeinput ← beta alpha alpha
3mode="unique"4input="beta alpha alpha"5if [ "$mode" = "unique" ]; thenvalues this stepbeta alpha alphainputif [ "$mode" = "unique" ]; then
4input="beta alpha alpha"5if [ "$mode" = "unique" ]; then6 command="sort | uniq"values this stepuniquemodecommand ← sort | uniq
5if [ "$mode" = "unique" ]; then6 command="sort | uniq"7 output="alpha beta"values this stepsort | uniqcommandoutput ← alpha beta
6 command="sort | uniq"7 output="alpha beta"8elsevalues this stepalpha betaoutputbeta alpha alphainputecho "$command -> $output"
11fi12echo "$command -> $output"outputsort | uniq -> alpha betavalues this stepsort | uniqcommandalpha betaoutput
mode ← reverse
3mode="reverse"4input="beta alpha alpha"values this stepreversemodeinput ← beta alpha alpha
3mode="reverse"4input="beta alpha alpha"5if [ "$mode" = "unique" ]; thenvalues this stepbeta alpha alphainputif [ "$mode" = "unique" ]; then
4input="beta alpha alpha"5if [ "$mode" = "unique" ]; then6 command="sort | uniq"values this stepreversemodecommand ← sort -r
8else9 command="sort -r"10 output="beta alpha alpha"values this stepsort -rcommandoutput ← beta alpha alpha
9 command="sort -r"10 output="beta alpha alpha"11fivalues this stepbeta alpha alphaoutputbeta alpha alphainputecho "$command -> $output"
11fi12echo "$command -> $output"outputsort -r -> beta alpha alphavalues this stepsort -rcommandbeta alpha alphaoutput
pipeline
A pipeline connects commands so each stage transforms the stream.
sort
`sort` orders lines before later processing.
uniq
`uniq` removes adjacent duplicate lines after sorting.