Renaming a lot of similarly named files

Renaming a lot of similarly named files

Post by Thomas La Por » Wed, 03 Aug 1994 06:32:08



I have a directory full of files (~150) that have names of the form
XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif
(where XXXX are numbers from 0001-0150) but I can't figure out how to do
it all at once, w/o having to rename them individually.

My first thought was do it like DOS: mv ????.jpg.gif ????.gif but that
resulted in a "No Match" message. "mv *.jpg.gif *.gif" resulted in files
like XXXX.jpg.gif.gif. The basename function seems to provide most of what
I need, but I don't know enough programming to figure out how to write a
shell script using it. I used basename with foreach and produced a file like:

0001
0002
0003
etc., but I don't know what to do with that file, if anything. Any
suggestions? (I'm quite sure I've made this into a much more difficult
problem than it is, but everything I know about Unix I learned from the
man pages!)

Thanks for any help. -- Tom
--
"Laugh and the world laughs with you;                  Thomas A. La Porte

 
 
 

Renaming a lot of similarly named files

Post by A.K.Srikan » Thu, 04 Aug 1994 00:26:02



Quote:> I have a directory full of files (~150) that have names of the form
> XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif
> (where XXXX are numbers from 0001-0150) but I can't figure out how to do
> it all at once, w/o having to rename them individually.

> My first thought was do it like DOS: mv ????.jpg.gif ????.gif but that
> resulted in a "No Match" message. "mv *.jpg.gif *.gif" resulted in files
> like XXXX.jpg.gif.gif. The basename function seems to provide most of what
> I need, but I don't know enough programming to figure out how to write a
> shell script using it. I used basename with foreach and produced a file like:

> 0001
> 0002
> 0003
> etc., but I don't know what to do with that file, if anything. Any
> suggestions? (I'm quite sure I've made this into a much more difficult
> problem than it is, but everything I know about Unix I learned from the
> man pages! Thanks for any help. -- Tom
> --

This should do the trick.

#!/bin/sh
ls -1 *.jpg.gif | cut -f1 -d. > list

for ZNAME in `cat list`
do
  mv $ZNAME.jpg.gif $ZNAME.gif
done
rm -f list

Srikanth

---
-------------------------------------------------------------------------------
                    #include "std/disclaimer.h"
Ayikudy K. Srikanth      Software Engineer        Wellfleet Communications Inc.

Ph: (508) 436-8226       Fax : (508) 670-8760     Billerica, MA 01821

 
 
 

Renaming a lot of similarly named files

Post by Thomas La Por » Thu, 04 Aug 1994 08:27:03


Thank you to all who responded to my query. I apologize for posting a faq.
I received a great response (and a great variance in method). Thanks.

                                                -- Tom
--
"Laugh and the world laughs with you;                  Thomas A. La Porte

 
 
 

Renaming a lot of similarly named files

Post by Robert Co » Thu, 04 Aug 1994 06:33:40



Quote:> I have a directory full of files (~150) that have names of the form
> XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif

  [rest deleted]

Quote:> Thanks for any help. -- Tom

Hi,

Here is what I use.  If the script below is called changename, then type

changename jpg.g .g

or anything similar.

Ciao,
--
Robert Cole                           \
Institute of Geophysics               |/  NZ :-)
Victoria University of Wellington    /}

---------------------  cut here ----------------------------------------
#!/bin/csh
# changename
# 2 May 1994 RAC
#
if($#argv < 2) then
  cat << EOF

changename string1 string2

string1 is substring to search for
string2 is substring to replace with

EOF
  exit
endif
foreach file (*$1*)
set nfile=`echo $file | sed s/$1/$2/`
mv $file $nfile
end

--

 
 
 

Renaming a lot of similarly named files

Post by Andrew Mad » Thu, 04 Aug 1994 00:45:19


there is some PD soft. available called mmv
it should do what you want, but I can't remember where I got it from
try using archie to locate it

--
Andrew Madej
Atmospheric Environment Service
ARMP Division                           phone : (416) 739-4611
4905 Dufferin Street                    fax :     (416) 739-4211

Canada (Eh!)
M3H 5T4

 
 
 

Renaming a lot of similarly named files

Post by Sahir Siddiq » Thu, 04 Aug 1994 13:01:07



   > I have a directory full of files (~150) that have names of the form
   > XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif

   Using (t)csh:
   % foreach file (*.jpg.gif)
        mv $file.jpg.gif $file.gif
        end
   %
--
Sahir N. Siddiqui                     Res: (201) 217-0952
S-1351, Stevens Institute of Technology, Hoboken NJ 07030        ))))
                                                                oo-)

WWW:    http://menger.eecs.stevens-tech.edu/~sahirns/

 
 
 

Renaming a lot of similarly named files

Post by Bill Cull » Thu, 04 Aug 1994 12:44:02



> I have a directory full of files (~150) that have names of the form
> XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif
> (where XXXX are numbers from 0001-0150) but I can't figure out how to do
> it all at once, w/o having to rename them individually.

Try this:

#/bin/sh
for i in ????.jpg.gif
do
  mv $i `basename $i .jpg.gif`.gif
done

Note that this will catch all files of format ????.jpg.gif, not
just those between 0001-0150. If this is a problem then you may
need to modify the script.

Hope this helps.

> Thanks for any help. -- Tom
> --
> "Laugh and the world laughs with you;             Thomas A. La Porte


-----------------------------------------------------------------------------
 #define STANDARD_DISCLAIMER 1  /*              Bill Cullen               */
 'Okay, honey. Now we go out    /*      Tom Price, Western Australia      */

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

Renaming a lot of similarly named files

Post by Phil Cra » Fri, 05 Aug 1994 00:12:27




Quote:> I have a directory full of files (~150) that have names of the form
> XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif
> (where XXXX are numbers from 0001-0150) but I can't figure out how to do
> it all at once, w/o having to rename them individually.

[deletions]
Here's my stab at this, I'm sure others will have different (and probably
more elegant) methods, but here goes anyway:

for x in `ls -1` # Note: ` not '
do
        echo $x # Just so you know which file you're on
        XXXX=`echo $x| cut -f1 -d"."
        JPG=`echo $x | cut -f2 -d"."
        GIF=`echo $x | cut -f3 -d"."
        mv $x $XXXX.$GIF
done

You may want to make a copy of the directory before letting this
loose on it!
Usual disclaimers - I accept no responsibility for loss, damage
etc.etc.etc.etc.........

Good Luck!
--

AT&T Istel Ltd., Redditch, UK
#include <std/disclaimer>
Plain .sig, not an original thought in my head...........

 
 
 

Renaming a lot of similarly named files

Post by James Tilghm » Sat, 06 Aug 1994 04:10:24





>   > I have a directory full of files (~150) that have names of the form
>   > XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif

>   Using (t)csh:
>   % foreach file (*.jpg.gif)
>    mv $file.jpg.gif $file.gif
>    end
>   %

Actually, this won't work. It'll look for files with the extension of
``.jpg.gif.jpg.gif'' . And if it did find any, it would rename them with the
extension ``.jpg.gif.jpg.gif.gif'' . The correct way in (t)csh would be
(much like the version posted for sh by Mr. Cullen):

% foreach file (*.jpg.gif)
mv $file `basename $file .jpg.gif`.gif
end
%

I'm not sure, but this *might* work:
% foreach file (*.jpg.gif)
mv $file "$file:h".gif
end

James Tilghman

 
 
 

Renaming a lot of similarly named files

Post by Praveen C. Pu » Sun, 07 Aug 1994 00:41:30



|> I have a directory full of files (~150) that have names of the form
|> XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif
|> (where XXXX are numbers from 0001-0150) but I can't figure out how to do
|> it all at once, w/o having to rename them individually.
|>
|> My first thought was do it like DOS: mv ????.jpg.gif ????.gif but that
|> resulted in a "No Match" message. "mv *.jpg.gif *.gif" resulted in files
|> like XXXX.jpg.gif.gif. The basename function seems to provide most of what
|> I need, but I don't know enough programming to figure out how to write a
|> shell script using it. I used basename with foreach and produced a file like:
|>
|> 0001
|> 0002
|> 0003
|> etc., but I don't know what to do with that file, if anything. Any
|> suggestions? (I'm quite sure I've made this into a much more difficult
|> problem than it is, but everything I know about Unix I learned from the
|> man pages!)
|>
|> Thanks for any help. -- Tom
|> --
|> "Laugh and the world laughs with you;                    Thomas A. La Porte

Use the following shell script:

#! /bin/sh

for i in *
do
   j=`echo $i | sed 's/\.jpg//'`
   mv $i $j
done

--
Praveen Puri
Domestic Project Group
Motorola
"Have sh, will travel"

 
 
 

Renaming a lot of similarly named files

Post by Max Heffl » Sun, 07 Aug 1994 10:49:44



Quote:>I have a directory full of files (~150) that have names of the form
>XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif
>(where XXXX are numbers from 0001-0150) but I can't figure out how to do
>it all at once, w/o having to rename them individually.

foreach i (*.jpg.gif)
mv $i `basename $i .jpg.gif`.gif
end
--

  ___________________________________________________
  / // /// // /// // /// // /// // /// // /// // ///
 ---------------------------------------------------
 
 
 

Renaming a lot of similarly named files

Post by Geoffroy CMCL SAULNI » Wed, 03 Aug 1994 22:24:51


>I have a directory full of files (~150) that have names of the form
>XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif
>(where XXXX are numbers from 0001-0150) but I can't figure out how to do
>it all at once, w/o having to rename them individually.

>Thanks for any help. -- Tom
>--
>"Laugh and the world laughs with you;              Thomas A. La Porte


you could try using foreach, viz:

foreach {i} mv $i.jpeg.gif $i.gif;

or something like that - anyone else know the syntaxe better?

---
===============================================================


===============================================================

 
 
 

Renaming a lot of similarly named files

Post by Guruswamy Kows » Thu, 11 Aug 1994 00:30:53




Quote:

>>I have a directory full of files (~150) that have names of the form
>>XXXX.jpg.gif which I want to rename so that they are of the form XXXX.gif
>>(where XXXX are numbers from 0001-0150) but I can't figure out how to do
>>it all at once, w/o having to rename them individually.

>you could try using foreach, viz:

>foreach {i} mv $i.jpeg.gif $i.gif;

>or something like that - anyone else know the syntaxe better?

How about this:

~>foreach i (*.jpg.gif)
  set j=$i:r                # if $i is test.jpg.gif, $j = test.jpg
  mv $i $j:r
  end
--

<a href="http://www.ucs.usl.edu/~kxg5947/me.html>My Home page</a>|ered what I w
I am not my sysadmin. I don't do Emacs. I am a student and that's|as going to d
who I am and that's what I do. - Peter Kaine, paraphrased        |o here!

--

<a href="http://www.ucs.usl.edu/~kxg5947/me.html>My Home page</a>|ered what I w
I am not my sysadmin. I don't do Emacs. I am a student and that's|as going to d
who I am and that's what I do. - Peter Kaine, paraphrased        |o here!

 
 
 

1. renaming lots of files

Hi.

I need to rename lots of files in one of my directories.   I would like
to move all the files ending in .f to .F
I tried futilely to do
mv *.f *.F
but it doesn't work.  I am working on a Linux system, but I don't think
that is what is causing the "problem" - I probably just don't have the
right command.   Is there a way to move multiple files like this?   What
command would I have to type?

Thanks for your help.

2. System Performance Issues

3. ksh...newbie alert..newbie alert

4. Renaming lots of files

5. Help! kernel(1.2.9) compiling errors

6. How to rename a lot of files into lower case?

7. HP-UX 10.01 backpup using 'dump' questions

8. newbie need to rename lots of files

9. How to rename a lot of files ?

10. Renaming lots of files

11. Help using awk and bash script to copy and rename lots of index.htm files

12. how can rename the file name to what get from pipe?