i am trying to figure out how to solve the following problem:
I have a directory with lots of pictures, but none of them have any file
extensions. There are different formats, actually only .jpg and .bmp
Is there a way to automatically add the missing file extensions with a
script ? There is the command "file" which gives out what kind of format a
file has, for instance ...
florian@linux: /data> file image01
image01: JPEG image data, EXIF standard 0.73, 10752 x 2048
Something like this might work for me ...
#Script
for datei in *
do
if
file $datei="JPEG"*
then
extension=".jpeg"
else
extension=".bmp"
fi
done
I`ve tried the script but it does not work - i can`t get the
if file $datei="JPEG"*
part to work.
Maybe there`s a more simple way ?
Thanks for any help,
Florian
This is tailor made for the case statement.
case `file $i` in
*JPEG*) ext="jpg";;
*GIF*) ext="gif";;
...
esac
I didn't have a BMP file on my Unix system to test with, but you should be
able to get that part working...
> I didn't have a BMP file on my Unix system to test with, but you should be
> able to get that part working...
It`s working ! Thanks a lot !!!
Florian
if file $datei | grep JPEG >/dev/null; then
...
fi
or
case `file $datei` in
*JPEG*) ... ;;
esac
> then
> extension=".jpeg"
> else
> extension=".bmp"
> fi
> done
>
> I`ve tried the script but it does not work - i can`t get the
> if file $datei="JPEG"*
> part to work.
> Maybe there`s a more simple way ?
You can also test more than one file at a time:
file * | grep JPEG | awk -F : '{print $1}'
--
William Park <openge...@yahoo.ca>
Open Geometry Consulting, Toronto, Canada
William Park wrote:
<snip>
> You can also test more than one file at a time:
> file * | grep JPEG | awk -F : '{print $1}'
>
No need for both grep AND awk:
file * | awk -F : '/JPEG/{print $1}'
Ed.