- #!/bin/bash
- # sort_uniq.sh
- : << EOF
- runcmd="bash sort_uniq.sh m n"
- commands | output
- --------------------------------------------------------------
- cat m | xargs | 1 2 3 a b c
- cat n | xargs | 3 a b c d e
- runcmd n+m | xargs | a b c d e 1 2 3
- runcmd "m&&n" | xargs | a b c 3
- runcmd "m+n-m&&n" | xargs | d e 1 2
- runcmd "m-n&&m" | xargs | 1 2
- runcmd "n-m&&n" | xargs | d e
- EOF
- plus()
- {
- sort -g ${1} ${2} | uniq ${3}
- }
- mius()
- {
- sort -g <(plus ${1} ${2} -d) ${3} | uniq -u
- }
- case ${3} in
- "${1}+${2}"|"${2}+${1}") plus ${1} ${2} ;;
- "${1}&&${2}"|"${2}&&${1}") plus ${1} ${2} -d ;;
- "${1}-${1}&&${2}"|"${1}-${2}&&${1}") mius ${1} ${2} ${1} ;;
- "${2}-${1}&&${2}"|"${2}-${2}&&${1}") mius ${2} ${1} ${2} ;;
- "${1}+${2}-${1}&&${2}"|"${1}+${2}-${2}&&${1}"|"${2}+${1}-${1}&&${2}"|"${2}+${1}-${2}&&${1}") plus ${1} ${2} -u ;;
- esac