9/24 I have a directory with a bunch of image files names DSCNxxxx.jpg.
What's the quickest way to rename them all to Dscnxxxx.jpg? (just
changing the capitalization of the first 4 letters).
\_ foreach i (*.jpg)
mv $i `echo $i | sed -e s/DSCN/Dscn/`
end
I'm a hardware engineer and even I can come up with something
\_ You're assuming the OP has csh access to the directory.
\_ Okay, the why don't you just "dir" the files to a
text file, send it to your soda account, write a script
to change the names (DOS batch file), and viola.
\_ ObCygwin
\_ I'm looking for a one-liner that actually works... this
gives me "i: Undefined variable.". This is on linux and I do
have csh access. The perl suggestion below is a good idea but
it's overkill for what I'm doing right now. -op
\_ In Perl:
#!/usr/local/bin/perl
#
# Usage: rename perlexpr [files]
($regexp = shift @ARGV) || die "Usage: rename perlexpr [filenames]\n";
if (!@ARGV) {
@ARGV = <STDIN>;
chomp(@ARGV);
}
foreach $_ (@ARGV) {
$old_name = $_;
eval $regexp;
die $@ if $@;
rename($old_name, $_) unless $old_name eq $_;
}
exit(0);
Use 's/DSCN/dscn/' for the regex at the commandline or just
modify the $regex variable.
\_ Your OS?
\_ What you want is a nice perl script that renames it to
YYYYMMDD_HHMMSS_xxxx.jpg. This is the way to archive images.
Besides the image, the time is the next most important thing,
but with Windows and day light saving time and time zone, and
that sometime you forget to set the camera's clock correctly
when you travel, relying on file timestamp and exif time is
really not a good idea. Embed the picture time into the filename
is a permanent way to record the time of a photo.
\_ If you are using 4NT, just do "ren DSCN* Dscn*"
\-ls | awk '{print "mv " $1" "$1}' | sed 's/ DSC/Dsc//' | sh
\_ This works in NT Command Prompt. You don't need 4NT.
\-ls | awk '{print "mv " $1" "$1}' | sed 's/ DSCN/Dscn//' | sh
--psb
\_ you should just use gsub in your awk.
\- as i said last time this came up on the motd, anybody
asking a question like this isnt going to be familiar
with complicated awk or sed, backrefs etc. So it's best to
make something easy to modify. i suppose i should have
used the nth match for sed. i would personally just do
this in emacs. --psb |