Re: upper/lower case

"[email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>

 This shell code generates the "sed" code to be run on the csv file to generate the required data...
 

 #!/bin/sh -u
 

 # Usage: my_shell.sed_file   input.csv    3
 

 maxFld() {

    < $1 sed -e 'y/;/\n/;q' | sed -ne '$='
 }
 

 emit() {

    case $1 in 0 ) return;; esac
    while :; do

       case $1 in "$#" ) shift; break;; esac
       set "$@" 'N'
    done
    echo 'N' ${1+"$@"}

 }
 

 genCode() {
    lc='s/.*\n//;s/.*/\L&/;s/\<[a-z]/\u&/g'
    pr='H;g;y/\n/;/;b'
 

    set \
       $(emit $c_2)               \
       'h'                              \
       'N'                              \
       "$lc"                           \
       $(emit $(expr $N - $c)) \
       "$pr"                           \
    ;
 

    (IFS=";"; echo "$*")
 }
 

 c=$2;
 N=$(maxFld $1);
 c_2=`expr $c - 2`
 

 code=$(genCode)
 

 # finally...
 

 < $1 sed -e '1!y/;/\n/'    |    sed -e "1b;$code"

 

 



[Non-text portions of this message have been removed]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.