On Tue, Jun 25, 2002 at 12:12:06PM -0600, [EMAIL PROTECTED] wrote:
> 
> I want to rename a bunch of files in one go. After Googling I got this: 
> 
> $ find -name "*.abc" -exec echo {} {} \; | sed -e "s/\.abc/\.def/" |
> awk �{print $2 " " $1}� | xargs -n 2 -t mv
> >mv ./sombrero.abc ./sombrero.def 
> >mv ./steams.abc ./steams.def 
> >mv ./sunset3.abc ./sunset3.def 
> >mv ./swirlbox.abc ./swirlbox.def 
> >mv ./smoke.abc ./smoke.def
> 
> It changes the file extention from .abc to .def ! 
> 
> OK, but instaed of simply changing the file extention from .abc to .def , I 
> want .s01, .s02 ... .s12 etc. i.e. the pipe command should pick up first 
> letter of the file-name ( "s" in this case ) and the rest 2 chars of file 
> extention should have "01", "02" etc in increasing order for that particular 
> letter.
> The extention should be exactly 3-letter word in the above format. 
> 
> PS: I was thinking of doing it thru "C" , but this seems to be much easier 
> trick. Good old Linux ! 
> 
> 
---end quoted text---

There are many ways to skin a cat. For renaming extensions,
this script should do fine. You seemed to have googled some
geeky site. Actually the mv line within a loop is enough !

---------------<snip>------------------- 
#!/bin/bash
# Renaming File Extensions Script (rfes)
# Usage: rfes old_extn new_extn

if [ $# -ne 2 ]
then
  echo "Usage: `basename $0` old_suffix new_suffix"
  exit 1
fi

for file in *.$1
do
  mv $file ${file%$1}$2
done

exit 0
--------------</snip>---------------------


For your requirement of changing the extension dynamically
with extension increments  see if you can generate the new
extension, instead  of using  $2 ... do it as homework :-)
Not difficult if you get the idea !

Come back on personal mail, if you get stuck.  

Bish

--
:
####[ Linux One Stanza Tip (LOST) ]###########################

Sub : Simple console calculator (#2)                 LOST #222

A command line calculator which also understands precedence:
Try :$echo "(12 + 2) / (5 + 2) ^ 2" | bc     ### integer maths
Or  :$echo "scale=4; (17 / 3) + 0.517" | bc  ### 'real' maths
Note:'scale' is the decimal round off figure (real numbers).

####<[EMAIL PROTECTED]>####################################
:


-------------------------------------------------------
This sf.net email is sponsored by: Jabber Inc.
Don't miss the IM event of the season | Special offer for OSDN members! 
JabberConf 2002, Aug. 20-22, Keystone, CO http://www.jabberconf.com/osdn
_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to