Re: batch rename
Jeff Laine wrote: My goal is to rename several files in such a way as to decapitalize starting letters in their names. The solution seems to be simple but I'm stuck. What should I use? awk/sed or write some shell-script? I found myself at this point once too, and then I discovered /usr/ports/sysutils/rename. Sure, its not as crazy as krename (it wont read any metadata), but it runs in a terminal, is written in C and supports extended regular expressions. JimBow ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: batch rename
On Jan 5, 2008 6:34 AM, Jeff Laine <[EMAIL PROTECTED]> wrote: > My goal is to rename several files in such a way as to decapitalize starting > letters in their names. > The solution seems to be simple but I'm stuck. What should I use? awk/sed or > write some shell-script? If you want to forsake the command line, krename is great for this kind of thing. From the website: What is KRename ? Rename is a powerful batch renamer for KDE. It allows you to easily rename hundreds or even more files in one go. The filenames can be created by parts of the original filename, numbering the files or accessing hundreds of informations about the file, like creation date or Exif informations of an image. http://www.krename.net/ -- Colin Brace Amsterdam ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: batch rename
On 05/01/08 Aryeh M. Friedman said: > This assumes tcsh: > > foreach i (`ls [A-Z][a-z]*`) > mv $i `echo $i|tr 'A-Z' 'a-z'` > end sh version: for i in * do mv $i `echo $i | tr 'A-Z' 'a-z'` done Mike -- Michael P. Soulier <[EMAIL PROTECTED]> "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." --Albert Einstein pgpfuDJn7M03a.pgp Description: PGP signature
Re: batch rename
Aryeh M. Friedman wrote: > My goal is to rename several files in such a way as to decapitalize > > starting letters in their names. The solution seems to be simple > > but I'm stuck. What should I use? awk/sed or write some > > shell-script? > > This assumes tcsh: > > foreach i (`ls [A-Z][a-z]*`) > mv $i `echo $i|tr 'A-Z' 'a-z'` > end This will disfunction if the names have embedded white spaces. I happen to batch rename songs etc. which almost invariably have white spaces and other horrors. So i use something like mv "$i" `echo $i|sed -e 's/ */_/g' -e '.' ` Sed has the advantage you can do several transformations at one stroke, and fine tune the transformations. Double quotes avoid that the shell breaks names on white space. -- Michel TALON ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: batch rename
In the last episode (Jan 05), Jeff Laine said: > My goal is to rename several files in such a way as to decapitalize > starting letters in their names. The solution seems to be simple but > I'm stuck. What should I use? awk/sed or write some shell-script? Best way is with ports/misc/mmv: mmv "?*" "=l1=2" If you use zsh, you can use the zmv function to do the same thing: autoload -U zmv zmv '([A-Z])(*)' '${(L)1}$2' Both of the above will detect filename collisions and tell you what won't work. If you know there aren't any collisions, you could do this (zsh again): for i in [A-Z]* ; do mv $i ${i[1]:l}${i[2,-1]} done -- Dan Nelson [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: batch rename
On 05-Jan-08, at 11:31 AM, Aryeh M. Friedman wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jeff Laine wrote: Hi to all. My goal is to rename several files in such a way as to decapitalize starting letters in their names. The solution seems to be simple but I'm stuck. What should I use? awk/sed or write some shell-script? This assumes tcsh: foreach i (`ls [A-Z][a-z]*`) mv $i `echo $i|tr 'A-Z' 'a-z'` end tr will decapitalize all the letters in the string. regards, shantanoo ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: batch rename
On 05-Jan-08, at 12:16 PM, Aryeh M. Friedman wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Shantanoo Mahajan wrote: On 05-Jan-08, at 11:31 AM, Aryeh M. Friedman wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jeff Laine wrote: Hi to all. My goal is to rename several files in such a way as to decapitalize starting letters in their names. The solution seems to be simple but I'm stuck. What should I use? awk/sed or write some shell-script? This assumes tcsh: foreach i (`ls [A-Z][a-z]*`) mv $i `echo $i|tr 'A-Z' 'a-z'` end tr will decapitalize all the letters in the string. You can replace it with the following sed then sed s/^[A-Z]/[a-z]/ In bash shell: $ echo AsD | sed s/^[A-Z]/[a-z]/ [a-z]sD I thought about this while sending earlier reply, but was unable to get it working properly. regards, shantanoo ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: batch rename
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Shantanoo Mahajan wrote: > > On 05-Jan-08, at 11:31 AM, Aryeh M. Friedman wrote: > >> -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 >> >> Jeff Laine wrote: >>> Hi to all. >>> >>> My goal is to rename several files in such a way as to >>> decapitalize starting letters in their names. The solution >>> seems to be simple but I'm stuck. What should I use? awk/sed or >>> write some shell-script? >> >> This assumes tcsh: >> >> foreach i (`ls [A-Z][a-z]*`) mv $i `echo $i|tr 'A-Z' 'a-z'` end >>> > > tr will decapitalize all the letters in the string. > You can replace it with the following sed then sed s/^[A-Z]/[a-z]/ - -- Aryeh M. Friedman FloSoft Systems, Java Developer Tools http://www.flosoft-systems.com Developer, not business, friendly. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.4 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHfyeujRvRjGmHRgQRAq93AKCX5RmMVI436s4fHnFL5Lbf7ZFu9QCfXnQi BmYgPvB6m+1WlpeF9YXQd80= =SsIF -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: batch rename
On 05/01/2008, Aryeh M. Friedman <[EMAIL PROTECTED]> wrote: > > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Jeff Laine wrote: > > Hi to all. > > > > My goal is to rename several files in such a way as to decapitalize > > starting letters in their names. The solution seems to be simple > > but I'm stuck. What should I use? awk/sed or write some > > shell-script? > > This assumes tcsh: > > foreach i (`ls [A-Z][a-z]*`) > mv $i `echo $i|tr 'A-Z' 'a-z'` > end > Thanks! It was simple after all. Doh, I've never heard about "tr" before. -- --Jeff-- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: batch rename
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jeff Laine wrote: > Hi to all. > > My goal is to rename several files in such a way as to decapitalize > starting letters in their names. The solution seems to be simple > but I'm stuck. What should I use? awk/sed or write some > shell-script? This assumes tcsh: foreach i (`ls [A-Z][a-z]*`) mv $i `echo $i|tr 'A-Z' 'a-z'` end > > > TIA > - -- Aryeh M. Friedman FloSoft Systems, Java Developer Tools http://www.flosoft-systems.com Developer, not business, friendly. -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.4 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHfx1UjRvRjGmHRgQRAi7iAJ4kFwUQRj18O1DSP6D8KrO/0sOzrwCfZkgv zutJcCUMAlFfjpqhs5aF/Vw= =wuvQ -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
batch rename
Hi to all. My goal is to rename several files in such a way as to decapitalize starting letters in their names. The solution seems to be simple but I'm stuck. What should I use? awk/sed or write some shell-script? TIA -- --Jeff-- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Shell script--batch rename files
mvb (MV-Batch shell script) To the several people who wrote to me about my batch-rename shell script, and anyone else who may be interested, I have worked a lot on it the past few days and the latest version (1.5.5) and a screenshot and README is at: http://www.xscd.com/pub/mvb/ I'll try to keep subsequent versions, if any, in the same location. Because I am learning shell scripting, I appreciate any criticisms, comments or suggestions from more proficient programmers and users. The script works well for me, especially for quickly renaming image files that have been downloaded from my digital camera or from the Internet and sorted into directories by theme. Best wishes, Steve Doonan Portales, NM US -- A smooth sea has never made a good sailor. ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Shell script--batch rename files
Hello All-- I'm a novice shell programmer, but I thought I would begin to learn by writing a script that had a need for but could not find an equivalent of on the Internet. I decided to post it here (a) in case anyone else might find it useful and (b) to expose it to more experienced script authors who might be kind enough to offer helpful criticisms or suggestions. (the script appears in its entirety at the end of this email) I wrote the script (it works with /bin/sh or BASH) to address the following problem-- I have many folders of image files (from my digital camera, received as email attachments or downloaded from the Internet) that I have sorted into folders by theme (such as "friends," "family," "vacation_2003," etc.), and many of them have filenames I would like to change on a per-directory basis, either because they are too generic (IMG_0105.JPG, IMG_0106.JPG, etc.), or because the filenames have spaces or unusual characters within them, or simply to make all the filenames in each directory have the same root name with a unique numerical index appended, maintaining their original filename extension (or adding one, if desired). The script works on files in the shell's current directory only (and not on any subdirectories within), and renames every file (but not subdirectories or symbolic links) using a user-specified name followed by a numerical index, followed by the file's original filename extension (if there was any). On my machine I have titled the script mvb (like a "batch" version of mv), and it seems to work well so far during the couple months I have been working on it. Like I said, I post it here in case anyone else may find it useful and to learn from any criticisms, comments and suggestions it might generate. Thank you, Steve ---CUT-HEREshell-script-begins-on-next-line--- #!/bin/sh # # Change the path above to point to the location on # your computer of either the Bourne shell (sh) or # the BASH (Bourne Again) shell (bash). # # This shell script was written to "batch rename" files # (change the name of many files at once) in the # current working directory. # # For his personal use the author named this script # mvb (MV-Batch) in reference to the mv command # of *nix/Linux (which this script uses). # # Written by: Steve Doonan, Portales, NM US # Email: [EMAIL PROTECTED] # Date: October, 2003 # if [ $# -eq 0 ] then cat << _EOF_ -- You did not specify a NEWNAME for the files. After the name of the command please enter a SPACE followed by the name you would like all the files in the current directory to be renamed to. -- _EOF_ exit fi NEWNAME="$(echo "$1" | tr -Cs '[:alnum:]' '_')" cat << _EOF_ --- Rename files to--> $NEWNAME Current directory--> $(pwd) Continue? (Press RETURN or ENTER) TO QUIT, type q (then press RETURN or ENTER) FOR INFORMATION, type i (then press RETURN or ENTER) --- _EOF_ read CONTINUE case $CONTINUE in [!i]* ) exit ;; i ) cat << _EOF_ INFORMATION This shell script (Bourne or BASH) will RENAME all visible files (files that don't begin with a dot) in the current directory, to a name you specify, appending a numerical index to each filename so that each is unique, and retaining the original filename extension, if one exists. This script will NOT rename subdirectories or symbolic links contained within the current directory, nor will it descend into subdirectories to rename files within them. If the script does not see what looks like an existing valid FILENAME EXTENSION (3-4 characters following a dot at the end of a filename), it will ask for one. If you WANT to add a filename extension, just type 3 or 4 characters (i.e. jpg, txt, html), with or without a preceding dot--the script will provide the dot if you do not. If you do NOT want the filename to have an extension, just press RETURN or ENTER at that prompt without typing any characters, and no filename extension will be added. To QUIT this program at any time, press CONTROL-C To CONTINUE, press RETURN or ENTER _EOF_ read CONTINUE ;; esac INDEX=0 make_zero-padded_index_number () { INDEX=$(($INDEX + 1)) INDEX_COUNT="$(echo "$INDEX" | wc -c)" PADDING_ZEROS="$(ls "$(pwd)" | wc -l | tr '[:digit:]' '0' | tr -d '[:space:]')" INDEX_ALPHANUMERIC="$(echo "${PADDING_ZEROS}${INDEX}" | cut -c$INDEX_COU