Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace *.SGML to *.sgml please...

Status
Not open for further replies.

hendnov

Technical User
Feb 27, 2006
73
AU
Hi guys, I've tried to replace filename which is all extension in capital to lower case :
such as :
AMM.SGM
IPC.SGM

into
AMM.sgm
IPC.sgm

I've tried to use "sub", but seems "sub" function doesnt work in my awk solaris. any other idea or know why?

THX GUYS
 
here's one way:

cd /dir/with/your/files
for file in *.SGM
do
newname=$(basename $file .SGM).sgm
echo mv ${file} ${newname}
done

if satisfied with the result, omit the echo and run again.

HTH,

p5wizard
 
hi p5wizard,

I've tried your script, here it is :
****************************************
#!/bin/sh


cd /opt/adoc/input_data/boeing/sample
for file in *.SGM
do
newname=$(basename $file .SGM).sgm
echo mv ${file} ${newname}
done
******************************************

but they responded with this :
/opt/adoc/test: syntax error at line 7: `newname=$' unexpected

any idea why?

Cheers,
 
change
Code:
#!/bin/sh

TO

Code:
#!/bin/ksh


OR
change
Code:
newname=$(basename $file .SGM).sgm

TO

Code:
newname=`basename $file .SGM`.sgm

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
As Vlad pointed out, variable=$(command) is the korn shell equivalent to variable=`command` in bourne shell.

I assumed you knew about that...

HTH,

p5wizard
 
Hi Vgersh99,

I've changed it so it becomes :
***********************************************
#!/bin/ksh


cd /opt/adoc/input_data/boeing/sample
for file in *.SGM
do
newname='basename $file .SGM'.sgm
echo mv ${file} ${newname}
done
**************************************************
and the result it :

mv go.SGM basename $file .SGM.sgm
mv ipc.SGM basename $file .SGM.sgm

which I want :
mv go.SGM go.sgm
mv ipc.SGM go.sgm

Cheers mate,
 
use back-quotes

Code:
newname=`basename $file .SGM`.sgm

HTH,

p5wizard
 
yay...

It's working...
thx alot p5wizard...

CHEERS,
 
And you didn't need to change both the #!/bin/sh and the $() lines. Changing just one of 'em would have sufficed.

Korn shell understands both var=$(cmd) and var=`cmd`

Bourne shell only understands var=`cmd`

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top