user3300847
user3300847

Reputation: 1

converting the file format using shell script

i wanted to convert the format of all image files in a folder using the following shell script. My idea is to use the base name of the filename and using the same for naming the file to be converted. I gathered these lines from internet and could not meet my requirement. Thank u all.

for f in *.eps
do
 echo "converting format....."
 filename=`basename ${f}`   
 fbase=`$filename | cut -d'.' -f1`  
 extn = ${fbase}.png  
   convert -geometry 1000x1000 -density 300 -trim ${f} $extn
done 

Upvotes: 0

Views: 2935

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

I think you need something more like this:

#!/bin/bash
for f in *.eps
do  
  new=${f/eps$/png}
  echo Converting $f to $new
  convert -geometry 1000x1000 -density 300 -trim "$f" "$new"
done

Note:

The line commencing "new=" is performing a bash substitution in the variable "f", replacing "eps" at the end of the line (i.e. $) with "png".

Upvotes: 1

Related Questions