Mt Xia: Technical Consulting Group

Business Continuity / Disaster Recovery / High Availability
Data Center Automation / Audit Response / Audit Compliance

-
Current Location
-

css
  Downloads
    Scripts
      Korn
        K93_Unix

-

digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


AIX FREE DEMO UNIX
Automated AIX Deployment
Reduce your DC costs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com



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

-
uniq_k93
-
 


AIX FREE DEMO UNIX
Automated AIX Deployment
Reduce your DC costs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com