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


Mt Xia:
Technical Consulting Group

 

dos2unix_k93


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

Current:dos2unix_k93
Previous:
Home Page



#!/usr/bin/ksh93
################################################################
#### Program: dos2unix_k93
#### 
#### Description: Emulation of the Unix "dos2unix" command
#### 
#### Author: Dana French (dfrench@mtxia.com)
####         Copyright 2004
#### 
#### Date: 07/22/2004
#### 
################################################################
function dos2unix_k93 {
  typeset TRUE="0"
  typeset FALSE="1"
  typeset VERBOSE="${FALSE}"
  typeset VERYVERB="${FALSE}"
  typeset FNAME

  while getopts ":vV" OPTION
  do
    case "${OPTION}" in
        'v') VERBOSE="${TRUE}";;
        'V') VERYVERB="${TRUE}";;
        '?') print "Syntax: dos2unix_k93 file ..." && exit 1 ;;
    esac
  done
 
  shift $(( ${OPTIND} - 1 ))

  typeset STDIN="${1:+${FALSE}}"
  STDIN="${STDIN:-${TRUE}}"

#### Read in the data either from STDIN or one or more files
  if (( STDIN == TRUE ))
  then
      d2u_k93
  else
      for FNAME in "${@}"
      do
          exec 0<"${FNAME}"
            d2u_k93
          exec 0<&-
      done
  fi

  return 0
}
################################################################
function d2u_k93 {
    typeset LINE

    while read -r -- LINE
    do
        print -r -- "${LINE/%$'\r'/}"
    done
}
################################################################

dos2unix_k93 "${@}"

 

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