100% Spam Free Email | Contact Us | Products/Services | Korn Shell | MicroEMACS


Mt Xia:
Technical Consulting Group

 

uniq_k93


Contact Mt Xia for help with your shell scripting projects at 615.556.0456 or dfrench@mtxia.com

Current:uniq_k93
Previous:
Home Page



#!/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 "${@}"

 

For information regarding this page, contact Dana French ( dfrench@mtxia.com )
Copyright 2008 by Mt Xia Inc, All Rights Reserved