Re: upper/lower case

"Daniel Goldman [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
Thanks for sending the more complete file example. Here is one way to do 
it, in addition to the other suggestions.

$ cat input.txt
"id";"lastname";"firstname";"adress";"zip";"town"
"9515";"CRAIG";"PAUL";"3 Av Marie Curie";"75001";"Paris"
"355";"BROSNAN";"MARIE ODILE";"43 Rue PASTEUR";"75001";"Paris"
"85";"CONNERY";"JEAN-CHARLES";"7 Rue LECOURBE";"14256";"Seville"
"5315125";"MOORE";"JEAN-MARC";"12 Av PASTEUR";"47852";"Rome"

$ cat process.sh
input_file=$1
col_to_sed=$2

prev_col=`expr $col_to_sed - 1`
next_col=`expr $col_to_sed + 1`

cut -d ";" -f $col_to_sed $input_file > old_col.txt
cut -d ";" -f 1-$prev_col $input_file > cols_before.txt
cut -d ";" -f $next_col- $input_file > cols_after.txt

sed -r "1! {s/(.*)/\L\1/; s/\<(.)/\u\1/g}" < old_col.txt > new_col.txt

paste -d ";" cols_before.txt new_col.txt cols_after.txt

$ ./process.sh input.txt 3
"id";"lastname";"firstname";"adress";"zip";"town"
"9515";"CRAIG";"Paul";"3 Av Marie Curie";"75001";"Paris"
"355";"BROSNAN";"Marie Odile";"43 Rue PASTEUR";"75001";"Paris"
"85";"CONNERY";"Jean-Charles";"7 Rue LECOURBE";"14256";"Seville"
"5315125";"MOORE";"Jean-Marc";"12 Av PASTEUR";"47852";"Rome"

On the negative side, the shell script might need to be modified if you 
have cases where col_to_sed is the first or last column, so the script 
would end up more complicated.

On the positive side, it works, and (at least to me!) seems simple 
enough to understand and maintain.

Daniel

On 12/11/2015 12:34 AM, MOKRANI Rachid [sed-users] wrote:
> Hi,
>
> Thanks, but this solution (without -i)  show me the result and don't write/save the file.
>
> This is a file exemple. the original file has many more rows and columns
>
> "id";"lastname";"firstname";"adress";"zip";"town"
> "9515";"CRAIG";"PAUL";"3 Av Marie Curie";"75001";"Paris"
> "355";"BROSNAN";"MARIE ODILE";"43 Rue PASTEUR";"75001";"Paris"
> "85";"CONNERY";"JEAN-CHARLES";"7 Rue LECOURBE";"14256";"Seville"
> "5315125";"MOORE";"JEAN-MARC";"12 Av PASTEUR";"47852";"Rome"
>
>
> in my example I would apply the results of sed  (sed -i -r "s/(.*)/\L\1/; s/\<(.)/\u\1/g" )  only in column 3 (title firstname) .
>
> "id";"lastname";"firstname";"adress";"ZIP";"TOWN"
> "9515";"CRAIG";"Paul";"3 Av Marie Curie";"75001";"Paris"
> "355";"BROSNAN";"Marie Odile";"43 Rue PASTEUR";"75001";"Paris"
> "85";"CONNERY";"Jean-Charles";"7 Rue LECOURBE";"14256";"Seville"
> "5315125";"MOORE";"Jean-Marc";"12 Av PASTEUR";"47852";"Rome"
>
>
> Once obtained this result I could apply a sed command on the column of my choice.
>
> And for now I just can't  do it.  :-(
>
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.