Re: upper/lower case

"[email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
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]
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.