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


Mt Xia:
Technical Consulting Group

 

fgrep_k93


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

Current:fgrep_k93
Previous:
Home Page



#!/usr/bin/ksh93
################################################################
#### Program: fgrep_k93
#### 
#### Description: Emulation of the Unix "fgrep" command
#### 
#### Author: Dana French (dfrench@mtxia.com)
####         Copyright 2004
#### 
#### Date: 07/22/2004
#### 
################################################################
function fgrep_k93
{
  typeset TRUE="0"
  typeset FALSE="1"
  typeset FNAME=""
  typeset LINE
  typeset FLAB=""
  typeset SRCH="${1}"
  shift
  typeset STDIN="${1:+${FALSE}}"
  STDIN="${STDIN:-${TRUE}}"

  if (( STDIN == TRUE ))
  then
    printMatchLine_k93 SRCH FLAB
  else
    for FNAME in "${@}"
    do
      (( ${#} > 1 )) && FLAB="${FNAME}:"
      exec 0<"${FNAME}"
        printMatchLine_k93 SRCH FLAB
      exec 0<&-
    done
  fi
  return 0
}
################################################################
function printMatchLine_k93 {
  nameref SRCH="${1}"
  nameref FLAB="${2}"
  typeset LINE
  IFS=""
  while IFS="" read -r -- LINE
  do
    [[ "_${LINE}" = _*+(${SRCH})* ]] && print -r -- "${FLAB}${LINE}"
  done
  return 0
}
################################################################

fgrep_k93 "${@}"

 

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