LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-05-2006, 03:54 PM   #1
jonaster
LQ Newbie
 
Registered: Jun 2006
Distribution: SuSE
Posts: 4

Rep: Reputation: 0
Replacing a image filename with a regex pattern in a script


I have a image gallery where files are named in the format img_yyyymmdd_nnn_widthxheight.jpg, for example: img_19981117_001_320x240.jpg

I've written a script that creates a list of all the images in a file. But I need to replace the filename of the image with a regex pattern so it applies to same image with a diffrent size. (Since different sizes of the image have different filename).

How can I replace the image filename (img_19981117_001_320x240.jpg) with a regex pattern of the filename like: /^img_19981117_001_[0-9]*x[0-9]*\.jpg$/ using sed or awk?

#!/bin/sh

DIR="$1"

if [ "$DIR" = "" ] ; then
echo "ERROR: You need to specify dir."
exit -1;
fi

for a in `ls $DIR`
do
if [ ! -f "${DIR}/${a}/IMAGEDESC" ] ; then
echo "Creating IMAGEDESC in ${DIR}/${a}";
for b in `ls $DIR/$a/thumb`
do
echo "/${b}/ No Description" >> "${DIR}/${a}/IMAGEDESC"
done;
fi
done;

exit 0;
 
Old 09-05-2006, 07:02 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Something like "^img_[0-9]\{8\}_\{1\}[0-9]\{3\}_\{1\}[0-9]\{1,4\}x\{1\}[0-9]\{1,4\}\.jpg"?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script pattern matching thedude2010 Programming 9 06-02-2006 02:39 AM
Need text pattern compare script kscott121 Linux - Software 4 05-10-2004 01:13 PM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 09:22 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
replacing pattern with sed produces double realos Programming 1 10-17-2002 08:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration