I'm trying to rename a bunch of files that were named incorrectly. I know a little about regular expressions but I'm not very good at them.
Here is the image of the file names:
I'm trying to change the 20111116 at the beginning to 20101116 for all the files.
Also I want the format of the other files that do not contain the IMG_#### to be of the format YYYYMMDD Race #- name.jpg They are all correct in this folder but the other folders are different.
The command I used was
It worked for the first three files as seen in the picture however i ended up getting a find: 20111116 Race 1- Susumna 2.jpg: unknown option error.
Is there any experts on regular expressions that could lend me a hand?
You need to quote the pattern argument to -name, otherwise the shell expands it to many filenames if there are matches in the current directory. This garbles the find command since it expects a single word after -name.
In the directory listing in your image, the extension case varies; some are .jpg and some are .JPG. Neither your find command (what I see of it) nor your sed will handle the uppercase variant.
While there's nothing at all wrong with piping sed output into sh, it can be unreliable if there are odd filenames in the input. For example, a leading dash would probably confuse mv, so it's a good idea to use -- to disable option processing. Further, a double-quote in a filename, which is allowed and not unheard off in song/movie/image names, would unbalance the quotes and break the sh script.
If possible, I try to avoid that idiom (unless I am confident that the data is sane).
The following is a different approach to renaming all jpg/JPG files that begin with 20111116 in a tree rooted at the current directory (test on copies or backup your data before running, or change the mv command to echo until you are confident it will work correctly):
That worked perfectly. Thank you so much you are a life saver!
---------- Post updated at 01:33 PM ---------- Previous update was at 12:56 PM ----------
Sorry I have another quick question. If a file name is "20111129 Race 2_CC Dancer.jpg" for example and I wanted it to be "20101129 Race 2- CC Dancer". Instead of the underscore I need a dash and a space. Is there something I could add to this code? Or would I need to use a completely new code?
Hi guys,
I need a help with a query. Basically i want to know the difference between (0+01)* and ((0+01)*)* . It seems whatever string can be generated by the first RE can also be generated by second and they should essentially be same. Am i missing something? (1 Reply)
Hi all,
How am I read a file, find the match regular expression and overwrite to the same files.
open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat";
open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat";
while (<DESTINATION_FILE>)
{
# print... (1 Reply)
I like to loop a list of files which named file1, file2, file3, file4, etc
if I like to loop them all over
for f in file1, file2, file3, file4
do
echo "processing" $f
done
how to use a regular expression to loop file$i instead?
Thank you. (4 Replies)
Hey all! what matching expression might I use to match all characters included in \W, EXCEPT < and > ?
for example:
@tokens=split(/ ???? /,$string);
I've dubiously tried \W but this clips off the first letter of each "token", for some reason ... (2 Replies)
Folks;
I have 3 questions & any help with them would be really appreciated:
If i have a list of directories, for example:
/fs/pas/2007/4/6/2634210/admdat/examin
/fs/pas/2007/4/6/2634210/admdat2/stat
/fs/pas/2007/4/6/2634210/admdat3/data
/fs/pas/2007/4/6/2634210/im_2/0b.dcm
Now; my... (6 Replies)
hi
i need to wipe out something from giving path i have some thing like that :
pwd | sed 's/.*foo//'
it is working fine when I have path like : /blah/balh1/foo/moo
so it erasing me all that comes before the foo including the foo
but I have problem when I have dir by the name of... (7 Replies)
Hi - I am trying to ignore the following items from a list.
lp0
lp11
lp12
lp14
The following code works fine, but I was wondering if there was a tidier way to write the lp regular expression?
egrep -v "lp"
Thanks in advance. (3 Replies)