#!/usr/bin/ksh93 ################################################################ function usagemsg_paste_k93 { print " Program: paste_k93 The paste_k93 Korn Shell function/command writes to standard output lines consisting of sequentially corresponding lines of each given file, separated by a TAB character. Standard input is used for a file name of `-' or if no input files are given. Usage: ${1##*/} [-d DELIMITER-LIST] [-s] [-v] [-V] [-?] [-] [FILE]... Where: '-d DELIMITER-LIST' = Consecutively use the characters in DELIM-LIST instead of TAB to separate merged lines. When DELIM-LIST is exhausted, start again at its beginning. '-s' = Paste the lines of one file at a time rather than one line from each file. '-v' = Verbose mode '-V' = Very Verbose Mode Author: Dana French (dfrench@mtxia.com) Copyright 2004 \"AutoContent\" enabled" return 0 } ################################################################ #### #### Description: #### #### The paste_k93 Korn Shell function/command writes to #### standard output lines consisting of sequentially #### corresponding lines of each given file, separated by a #### TAB character. Standard input is used for a file name of #### `-' or if no input files are given. #### #### Assumptions: #### #### Dependencies: #### #### Products: #### #### Configured Usage: #### #### Details: #### ################################################################ function paste_k93 { typeset TRUE="0" typeset FALSE="1" typeset SERIAL="${FALSE}" typeset DELIM=$'\t' typeset VERBOSE="${FALSE}" typeset VERYVERB="${FALSE}" typeset LINE while getopts ":sd:" OPTION do case "${OPTION}" in 's') SERIAL="${TRUE}";; 'd') DELIM="${OPTARG}";; 'v') VERBOSE="${TRUE}";; 'V') VERYVERB="${TRUE}";; '?') print "Syntax: paste_k93 [-123] [-] file ..." && exit 1 ;; esac done shift $(( ${OPTIND} - 1 )) typeset FILE typeset FCNT="0" typeset MAX="0" for FILE in "${@}" do (( FCNT++ )) typeset STDIN="${FALSE}" typeset UNIT="3" if [[ "_${FILE}" = '_-' ]] then STDIN="${TRUE}" UNIT="0" fi (( STDIN == FALSE )) && eval exec ${UNIT}\<"${FILE}" eval unset ARRY_${FCNT} CNT=0 while read -u ${UNIT} -r -- LINE do eval ARRY_${FCNT}[CNT]="\"\${LINE}\"" (( CNT++ )) done (( CNT > MAX )) && (( MAX = CNT )) (( STDIN == FALSE )) && eval exec ${UNIT}\<\&- done if (( SERIAL == FALSE )) then for (( IDX=0; IDX < MAX; ++IDX )) do DIDX=0 DEL="" for (( FIDX=1; FIDX <= FCNT; ++FIDX )) do eval print -r -n -- "\"\${DEL}\${ARRY_${FIDX}[IDX]}\"" DEL="${DELIM:DIDX:1}" [[ "_${DEL}" = "_" ]] && DEL=$'\t' (( DIDX++ )) (( DIDX > ( ${#DELIM} - 1 ) )) && DIDX=0 done print done fi if (( SERIAL == TRUE )) then for (( FIDX=1; FIDX <= FCNT; ++FIDX )) do DIDX=0 DEL="" eval MAX="\"\${#ARRY_${FIDX}[*]}\"" for (( IDX=0; IDX < MAX; ++IDX )) do eval print -r -n -- "\"\${DEL}\${ARRY_${FIDX}[IDX]}\"" DEL="${DELIM:DIDX:1}" [[ "_${DEL}" = "_" ]] && DEL=$'\t' (( DIDX++ )) (( DIDX > ( ${#DELIM} - 1 ) )) && DIDX=0 done print done fi } ################################################################ paste_k93 "${@}"