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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with wildcards 2

Status
Not open for further replies.

biot023

Programmer
Nov 8, 2001
403
GB
If I wanted to do the Unix equiavlent of the DOS commands
ren *.tif *.TIF
or
ren *.pqo *.pez

...how would I do it?
& is there any helpful info on wildcards & commands in Unix that anyone could share?
Needily (as always),

Douglas JL If it don't make you laugh, it ain't true.
 
Hi,

In unix we don't have such thing. But, you can achieve the same using shell script. Creat a script with name ren which take two parameters like rename utility of dos and write the simple logic to rename the files.

if you want, reply to this forum, i will write it for you :)

regards,
Mahesh
 
Man, if you could, that would be fantastic!
I have no unix shell script experience, but I'm cool with C, so if you could put that together, I would be massively grateful!

Thanks a tonne,
Douglas If it don't make you laugh, it ain't true.
 
I thought at first this was an easy one, but I seems there isn't an straightforward way to do this in linux.
So I asked someone here at work who knows a whole lot more of it than I do.
You have to write a script for it.
Here goes...



>pico ren

#!/bin/sh
FILES=`ls *.tif`
for FILE in $FILES
do
BN=`basename $FILE .tif`
mv $FILE $BN.TIF
done

>chmod 777 ren
>./ren

and this should work. I have a linux tutorial on pdf, if you give me your email adres, I'll send it to you.


Good luck.

The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
Hi,

Here is a sample code for that. You can use it at command prompt like this ..
$ren .gif .bmp

remember that .. don't put *.gif or any extention with *. It's not that scalable :)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#!/bin/sh

if [ -z "$1" -a -z "$2" ]
then
echo "Incomplete arguments ..."
echo "Usage: $0 .old_ext .new_ext"
exit 1
fi

Replace="$1"
Replacewith="$2"

OldSuffix="."`echo $Replace | awk -F. '{print $2}'`
NewSuffix="."`echo $Replacewith | awk -F. '{print $2}'`

for file in *
do
CheckSuffix="."`echo $file | awk -F. '{print $2}'`
if [ "$CheckSuffix" == "$OldSuffix" ]
then
FileName=`basename $file $OldSuffix`
echo mv $file $FileName"$NewSuffix"
mv $file $FileName"$NewSuffix"
fi
done

>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I named it ren.sh and then executed it as ren.sh .sh .rsh

and the name became ren.rsh :):p

hope this is ok for you.

regards,
Mahesh
 

Hey, you can delete those two lines ...
here is the modified one ..

#!/bin/sh

if [ -z "$1" -a -z "$2" ]
then
echo "Incomplete arguments ..."
echo "Usage: $0 .old_ext .new_ext"
exit 1
fi

OldSuffix="$1"
NewSuffix="$2"

for file in *
do
CheckSuffix="."`echo $file | awk -F. '{print $2}'`
if [ "$CheckSuffix" == "$OldSuffix" ]
then
FileName=`basename $file $OldSuffix`
echo mv $file $FileName"$NewSuffix"
mv $file $FileName"$NewSuffix"
fi
done


regards,
Mahesh

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top