RE: upper/lower case

"MOKRANI Rachid [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
And Daniel suggestion retrun me.

cat input.txt 
"a";"b";"c";"d";"e";"f"
"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 
#!/bin/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

return me.

./process.sh input.txt 3
cut: only one type of list may be specified
Try 'cut --help' for more information.



-----Message d'origine-----
De : [email protected] [mailto:[email protected]] 
Envoyé : vendredi 11 décembre 2015 13:06
À : [email protected]
Objet : Re: upper/lower case

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.  :-(
>


------------------------------------
Posted by: Daniel Goldman <[email protected]>
------------------------------------

-- 

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

Yahoo Groups Links



__________________________
Avant d'imprimer, pensez à l'environnement ! Please consider the environment before printing ! 
Ce message et toutes ses pièces jointes sont confidentiels et établis à l'intention exclusive de ses destinataires. Toute utilisation non conforme à sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. IFP Energies nouvelles décline toute responsabilité au titre de ce message. This message and any attachments are confidential and intended solely for the addressees. Any unauthorised use or dissemination is prohibited. IFP Energies nouvelles should not be liable for this message.
__________________________
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.