[mdlug] batch name changes

Ingles, Raymond Raymond.Ingles at compuware.com
Thu Jan 24 14:50:44 EST 2013


Sure. A loop on the files, and use the "-b" option to the "file" command, and the "cut" utility, and you're just about set.

Here's an example:

#!/bin/sh

# Helps handle filenames with spaces
IFS=`printf '\n\t'`

for FILE in $*
do
 echo $FILE
 IS_IMAGE=`file -b $FILE | cut -f2 -d" "`
 if [ "image" = "$IS_IMAGE" ]; then
   IMAGE_TYPE=`file -b $FILE | cut -f1 -d" "`
   case $IMAGE_TYPE in
    GIF)
      echo "It's a gif!"
      mv $FILE $FILE.gif
    ;;
    JPEG)
      echo "It's a jpeg!"
      mv $FILE $FILE.jpg
    ;;
    *)
      echo "I dunno what to do with image type " $IMAGE_TYPE 
    ;;
   esac
 fi
done

> -----Original Message-----
> From: mdlug-bounces at mdlug.org [mailto:mdlug-bounces at mdlug.org] On
> Behalf Of Mike On Mobile
> Sent: Thursday, January 24, 2013 12:46 PM
> To: MDLUG's Main discussion list
> Subject: Re: [mdlug] batch name changes
> 
> Hi Gary:
> 
> This should be easy. Simply use the file utility in a shell script.
> If you need more information there are various utilities like those
> from image magic as well as EXIF libraries.  If you could send me a
> sample of files and the output you are looking for, I feel pretty
> confident that I could cook up a shell script in a few minutes.
> 
>  cheers, Mike
> 
> Garry Stahl <tesral at wowway.com> wrote:
> 
> >I have a lot of old amiga /iff image files.  converting is easy,
> howvwer....
> >
> >Amiga didn't use the extension to identify file types.  Ergo the
> image
> >files have no extensions.  I need to add them.  Without doing them on
> >at a time (to some 5000 files) or changingthe rest of the name.
> >
> >Suggestions please.  Outside of hooking up the Amiga.  It can do that
> >easily.  Directory Opus was Ghodd.
> >
> >--
> >Garry  AKA  --Phoenix--  Rising above the Flames.
> >
> >I have as much authority as the Pope, I just don't have as many
> people who believe it.
> >Star Trek mort. Viva la Star Trek admiraetur The Olde Phoenix Inn
> >http://phoenixinn.iwarp.com Metro Detroit Linux Users Group
> >http://www.mdlug.org
> >
> >_______________________________________________
> >mdlug mailing list
> >mdlug at mdlug.org
> >http://mdlug.org/mailman/listinfo/mdlug
> _______________________________________________
> mdlug mailing list
> mdlug at mdlug.org
> http://mdlug.org/mailman/listinfo/mdlug




More information about the mdlug mailing list