Re: upper/lower case

"Thierry Blanc [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
I just finished this parameter version

BTW, speed test was faulty, the testfile had ^M instead of newline. the
loop script takes about 145s vs. 1.2s


#!/bin/bash


INFILE=$1
COL=$2
let "MAXCOL = $COL + 1"
MYCOL="col$COL"

READ="$(seq  -f "col%g" -s " " $MAXCOL)"
WRITE="$(seq  -f "\$col%g" -s "," $MAXCOL)"


while IFS=',' read $READ
do
  eval TARGET="\$$MYCOL"
 
  eval col$COL="\"$(echo "$TARGET" | sed -r 's/(.*)/\L\1/;
s/\<(.)/\u\1/g' )\""
  eval echo  $WRITE

done <  $INFILE >$3

On 12/12/15 21:00, [email protected] [sed-users] wrote:
> Of course the while-loop script can also be made parameter driven:
>  
>
>  #!/bin/sh -u
>  
>
>  c=3;   # column to sed
>  d=\;;   # csv delimiter
>  
>
>  lc_code="$c!b;s/.*/\L&/;s/\<[a-z]/\u&/g";    # sed code to lowercase
>  pr_code="H;1h;\$!d;g;y/\\n/$d/";                # sed code to print line
>  
>
>  while IFS= read -r Line; do
>     set -f;
>     IFS=$d; set X $Line; shift;
>     set X $(printf '%s\n' "$@" | sed -e "$lc_code"); shift;
>     echo "$@" | sed -e "$pr_code";
>  done < input.txt
>
>  
>
>  HTH
>  
>
>  -Rakesh
>  
>
> ---In [email protected], <dgoldman@...> wrote :
>
>  Thanks for doing the speed test. Of course, another disadvantage of the 
>  while-loop script is that it hard codes (a b c d). To my understanding, 
>  the cut-paste script can be totally parameter-driven.
>  
>  Just double-checking: The post shows IFS=',' used for while-loop script. 
>  Was intended IFS=';' used in actual speed test?
>  
>  Daniel
>  
>  On 12/12/2015 12:57 AM, Thierry Blanc [sed-users] wrote:
>  > speed test
>  >
>  > My concerns about a shell while loop were correct. The while-do loop is
>  > much slower.
>  >
>  > 1.079455912 vs. .221387482
>  >
>  >
>  >
>  > while-loop script:
>  >
>  > #!/bin/sh
>  >
>  > START=$(date +%s.%N)
>  > while IFS=',' read a b c d
>  > do
>  > c="$(echo "$c" | sed -r 's/(.*)/\L\1/; s/\<(.)/\u\1/g' )"
>  > echo "$a ; $b ;$c ; $d"
>  >
>  > done < $1 > $2
>  >
>  > END=$(date +%s.%N)
>  > echo "$END - $START" | bc
>  >
>  > #endofscript
>  >
>  > cut-paste script:
>  >
>  > #!/bin/sh
>  >
>  > START=$(date +%s.%N)
>  >
>  > col_to_sed=3
>  >
>  > prev_col=`expr $col_to_sed - 1`
>  > next_col=`expr $col_to_sed + 1`
>  >
>  > cut -d \; -f -$prev_col < $1 > cols_before.txt
>  > cut -d \; -f $col_to_sed < $1 > cols_.txt
>  > cut -d \; -f $next_col- < $1 > cols_after.txt
>  >
>  > sed -e '1b;s/.*/\L&/;s/\<./\u&/g' < cols_.txt > cols_new.txt
>  >
>  > paste -d\; cols_before.txt cols_new.txt cols_after.txt > output.csv
>  >
>  > END=$(date +%s.%N)
>  > echo "$END - $START" | bc
>  >
>  > #endofscript
>  >
>  > 
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
> Posted by: [email protected]
> ------------------------------------
>



------------------------------------

------------------------------------

-- 

------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/sed-users/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/sed-users/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo Groups is subject to:
    https://info.yahoo.com/legal/us/yahoo/utos/terms/
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.