renaming files

 
Francesco_13
Regular Advisor

renaming files

Hello,
i want replace recusive all my files data-source.xml.pass with data-source .xml

form line command i can do it:

filename=/u10/app/oracle/10.1.2/esbiforms/j2ee/home/config/data-sources.xml.pass
newv=${filename%.*}
echo $newv
/u10/app/oracle/10.1.2/esbiforms/j2ee/home/config/data-sources.xml

but in a loop this not run for: bud sustitution

Can you help me?

thanks.
Regards.
8 REPLIES 8
john korterman
Honored Contributor

Re: renaming files

Hi Francesco,

could you please show us the loop?

regards,
John K.
it would be nice if you always got a second chance
Dennis Handly
Acclaimed Contributor

Re: renaming files

Do you know what the value of $filename is when it fails?
I tried an empty string and one without any "." and I didn't get that "bad substitution" error.
Francesco_13
Regular Advisor

Re: renaming files

Hello ,
thi t's my loop:

for i in `cat /home/as10g/lista_data_sources_pass.lst`
do
filename=$i
newvariable=${filename%.*.*}
echo $newvariable
done

======================
extract
solpro07:/usr/local/oracle> cat /home/as10g/lista_data_sources_pass.lst
/u10/app/oracle/10.1.2/esbiforms/j2ee/home/config/data-sources.xml.pass
/u10/app/oracle/10.1.2/esbiforms/j2ee/OC4J_BI_Forms/config/data-sources.xml.pass
Francesco_13
Regular Advisor

Re: renaming files

Hello Dennis,

"recambio.sh" 10 líneas, 170 caracteres
for i in `cat /home/as10g/lista_data_sources_pass.lst`
do
echo $i
filename=$i
echo $filename
echo ${filename%.*}
newvariable=${filename%.*.*}
echo $newvariable
done
======
result:
======
solpro07:/usr/local/oracle> sh recambio.sh
/u10/app/oracle/10.1.2/esbiforms/j2ee/home/config/data-sources.xml.pass
/u10/app/oracle/10.1.2/esbiforms/j2ee/home/config/data-sources.xml.pass
recambio.sh: sustitución errónea
Dennis Handly
Acclaimed Contributor

Re: renaming files

I tried your loop using sh and I can't duplicate it.

What locale are you using?
echo $LANG
Francesco_13
Regular Advisor

Re: renaming files

Hello,
dont'have $LANG

but it's all spanish

LC_COLLATE=es_ES.ISO8859-15
LC_NUMERIC=es_ES.ISO8859-15
LC_MESSAGES=es
LC_MONETARY=es_ES.ISO8859-15
LC_TIME=es_ES.ISO8859-15

I use Ksh

thanks.
Regards.
Dennis Handly
Acclaimed Contributor

Re: renaming files

>but it's all Spanish

I didn't try that exact locale before but it still doesn't fail with those. What OS version do you have? Any ksh patches?
Francesco_13
Regular Advisor

Re: renaming files

Hello ,
i have do it the renaming with other commands.


thanks to all

Francesco