Mt Xia: Technical Consulting Group
Business Continuity / Disaster Recovery / High Availability Data Center Automation / Audit Response / Audit Compliance
#!/usr/bin/ksh93 ################################################################ #### Program: uniq_k93 #### #### Description: Emulation of the Unix "uniq" command #### #### Author: Dana French (dfrench@mtxia.com) #### Copyright 2004 #### #### Date: 07/22/2004 #### ################################################################ function uniq_k93 { typeset TRUE="0" typeset FALSE="1" typeset OLDPREV="" typeset FNAME="" typeset STDIN="${1:+${FALSE}}" STDIN="${STDIN:-${TRUE}}" if (( STDIN == TRUE )) then getUniqLine_k93 OLDPREV else for FNAME in "${@}" do if [[ -f "${FNAME}" ]] then exec 0<"${FNAME}" getUniqLine_k93 OLDPREV exec 0<&- else print -u 2 "ERROR: \"${FNAME}\" does not exist or is not a regular file." fi done fi return 0 } ################################################################ function getUniqLine_k93 { nameref OLDPREV="${1}" typeset PREV="${OLDPREV}" typeset CURR IFS="" [[ ${OLDPREV} = "_" ]] && read -r -- PREV && print -r -- "${PREV}" while read -r -- CURR do [[ "_${PREV}" = "_${CURR}" ]] && continue print -r -- "${CURR}" PREV="${CURR}" done OLDPREV="${PREV}" return 0 } ################################################################ uniq_k93 "${@}"