Home About BC DR HA Support Training Download
You are here: Home/ Downloads/ Scripts/ Korn/ K93_Unix/ Please Login or Register

-
Current Location
-

js
  Downloads
    Scripts
      Korn
        K93_Unix
-
AIX Admin Methodology
Global Consolidation Project
All AIX admins should join
www.aixexpert.com


Join our LinkedIn Group
AIX Advanced Technical Experts
Contract Opportunities

www.LinkedIn.com

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


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

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

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com



#!/usr/bin/ksh93
################################################################
#### Program: fold_k93
#### 
#### Description: Emulation of the Unix "fold" command
#### 
#### Author: Dana French (dfrench@mtxia.com)
####         Copyright 2004
#### 
#### Date: 07/28/2004
#### 
################################################################
function fold_k93 {
  typeset TRUE="0"
  typeset FALSE="1"
  typeset SPACES="${FALSE}"
  typeset WIDTH="80"
  typeset WIDCNT="0"
  typeset VERYVERB="${FALSE}"
  typeset VERYVERB="${FALSE}"
  typeset FNAME

  while getopts ":sw:vV" OPTION
  do
    case "${OPTION}" in
        's') SPACES="${TRUE}";;
        'w') WIDTH="${OPTARG}";;
        'v') VERBOSE="${TRUE}";;
        'V') VERYVERB="${TRUE}";;
        '?') print "Syntax: fold_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
      while IFS="" read -r -- LINE
      do
        if [[ "_${LINE}" = "_" ]]
        then
          (( WIDCNT > 0 )) && print
          print
          WIDCNT="0"
        else
          if (( SPACES == TRUE ))
          then
              foldOnSpace_k93 WIDCNT "${LINE}" "${WIDTH}"
          else
              foldOnWidth_k93 WIDCNT "${LINE}" "${WIDTH}"
          fi
        fi
      done
  else
      for FNAME in "${@}"
      do
        if [[ -e "${FNAME}" ]]
        then
            exec 0<"${FNAME}"

            while IFS="" read -r -- LINE
            do
              if [[ "_${LINE}" = "_" ]]
              then
                (( WIDCNT > 0 )) && print
                print
                WIDCNT="0"
              else
                if (( SPACES == TRUE ))
                then
                    foldOnSpace_k93 WIDCNT "${LINE}" "${WIDTH}"
                else
                    foldOnWidth_k93 WIDCNT "${LINE}" "${WIDTH}"
                fi
              fi
            done
            exec 0<&-
        else
            print -u 2 "${0##*/}: ${FNAME}: No such file or directory"
            return 1
        fi
      done
  fi

  return 0
}
################################################################
function foldOnSpace_k93 {
  nameref WIDCNT="${1}"
  typeset LINE="${2}"
  typeset WIDTH="${3}"

  for FIT in ${LINE}
  do

    if (( ( WIDCNT + ${#FIT} + 1 ) < WIDTH ))
    then
      (( WIDCNT != 0 )) && print -r -n -- " "
      print -r -n -- "${FIT}"
      (( WIDCNT = WIDCNT + ${#FIT} + 1 ))

    elif (( ( WIDCNT + ${#FIT} + 1 ) == WIDTH ))
    then
      (( WIDCNT != 0 )) && print -r -n -- " "
      print -r -- "${FIT}"
      (( WIDCNT = 0 ))

    else
      print -r -n -- $'\n'"${FIT}"
      (( WIDCNT = ${#FIT} ))
    fi

  done
}
################################################################
function foldOnWidth_k93 {
  nameref WIDCNT="${1}"
  typeset LINE="${2}"
  typeset WIDTH="${3}"

  for FIT in ${LINE}
  do

    if (( ( WIDCNT + ${#FIT} + 1 ) < WIDTH ))
    then
      (( WIDCNT != 0 )) && print -r -n -- " " && (( WIDCNT++ ))
      print -r -n -- "${FIT}"
      (( WIDCNT = WIDCNT + ${#FIT} ))

    elif (( ( WIDCNT + ${#FIT} + 1 ) == WIDTH ))
    then
      (( WIDCNT != 0 )) && print -r -n -- " "
      print -r -- "${FIT}"
      (( WIDCNT = 0 ))

    else
      (( WIDCNT != 0 )) && print -r -n -- " " && (( WIDCNT++ ))
      (( PART = WIDTH - WIDCNT + 1))
      print -r -- "${FIT:0:PART}"
      print -r -n -- "${FIT:PART}"
      (( WIDCNT = ${#FIT} - PART ))
    fi

  done
}
################################################################

fold_k93 "${@}"

-
fold_k93
-
 


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

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

www.siteox.com

FREE Domain Registration
included with Web Site Hosting
Tools, Social Networking, Blog

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com