ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a script i use to convert and move files regularly uploaded to an image gallery.
Now those that send over the files (a mac shop) have decided that they will be sending them in compressed .sea files... this has a great compression ratio and will save mucho bandwidth and time - unfortunately my script assumes that the files in question are in the root of the directory and also that they are all image files.
I need to extend the script so that it unstuffs the .sea file and performs the conversion and subsequent functions to all files in the root and it's recursive directories. The .sea file will be in the /home/image/convert directory but will no doubt uncompress into it's own. I.e. a file called test.sea will extract to /home/image/convert/test
Also - i need to extend the search and replace for any unconventional characters in the file names. Right now it replaces spaces with a _ , i need to also replace any periods with a _
Any help or pointers is greatly appreciated
Cheers,
S.
Here is the original script -
#!/bin/bash
#####################################################################
IMAGEDIR='/home/image/convert/'
DATE=`date +%m-%d`
JPG='/usr/local/apache/htdocs/imagegallery/admin/mainimages/tmp/'
TIF='/usr/local/apache/htdocs/imagegallery/admin/mainimages/'
ERRORS='/tmp/errors'
LIST='/tmp/list'
RESULTS='/tmp/results'
CONVERTED='/tmp/converted'
IMAGES="*"
#####################################################################
# Convert files and log actions
#####################################################################
#
# Create three files - error, list and results.
#
# list = file listing of all files converted that day (size and name)
# errors = errors generated by conversion
# converted = output of file conversion
# results = results or errors of the conversion process
#
#####################################################################
cd ${IMAGEDIR}
# Rename files with spaces - replace the spaces with a _
# NEED TO ADD replace statement for .
#
find ${IMAGEDIR} -name '* *' -type f | sort | while read FILE
do
NEWFILE=`dirname "${FILE}"`/`basename "${FILE}" | sed 's/ /_/g;'`
mv "${FILE}" "${NEWFILE}"
done
#
# Populate list of files > generated each time and cleaned out at the end of the daily script
ls -lh ${IMAGEDIR} | awk ' { print $9 " " $5 } '>>$LIST
#
# THERE HAS TO BE A BETTER WAY TO DO THIS other than a blanket do..
#
for files in ${IMAGES}
do
(
echo converting ${files} >>$CONVERTED
#
# echo output from conversion to converted log file/convert the files/move the files and set permissions
#
convert ${files} -resize 800x600 -colorspace rgb ${files}.jpg >>$CONVERTED 2>&1
#
# mv files to web space and set permissions
#
mv ${files} ${TIF}${files}_${DATE}.tif
mv ${files}.jpg ${JPG}${files}_${DATE}.jpg
)
done
cd ${TIF}
chown nobody:nobody *.tif
chmod 664 *.tif
cd ${JPG}
chown nobody:nobody *.jpg
chmod 664 *.jpg
#
# Generate Result section
#
#
cat $CONVERTED |egrep "converting|error" >>$RESULTS
find seems to be part of your solution. find <dir> -type f will list all the files in a directory recursively.
To replace periods I guess you can use sed s/'\.'/'_'/. Another way to do it - just exchange one character to another - is to use tr.
find <dir> -type f | tr '[:punct:][:space:]' '_'
will probably do approximately what you want :)
*testing*
Hm, it seems that the [:space:] set will also match newline, but that is not a big problem.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.