OT? Bash Script

Gavin McDonald gavitron at gmail.com
Thu Sep 1 03:59:40 UTC 2005


On Aug 31, 2005, at 10:54 PM, Lokrin wrote:

>> Well, I don't even know where to start.  If you can point me to the  
>> right command I could probably google more...
>>
>> Anyway, I have a directory with several subdirectories in it.  I  
>> want to change file names in several ways.
>>
>> 1) lower-case everything
>> 2) strip out spaces and special characters.
>> 3) make jpg, jpeg, jpe, etc.. all into jpg
>>
>> And make sure that nothing collides, such as name.jpg and  
>> name.gif.  They have to have different names because of another  
>> program that makes jpg thumbnails of all images.  If necessary I'm  
>> willing to rename all the files to something like Image0001.jpg,  
>> image0002.gif, image0003.gif, etc..  And, if possible, do hidden  
>> folders and files also.
>>
>> Anyway, if anyone can get me started I'd appreciate it.
> 
>Pick up a copy of Learning Perl and get to reading.  This is simple  
>enough, but you want to learn it... not have someone do it for you,  
>right?

Y'know,

Having done this in both Perl, and Bash, I'd argue that the Perl solution,
while more elegant, and more versatile, is harder to learn from scratch.  
The directory recursion provided by "for file in `ls foo` ; do" is far
easier, IMHO.  Though maybe cpan has a module for it that I neglected to
grab at the time.  Of course, the easier file IO in bash comes at the
expense of Regex's. (sed/awk anyone...) Maybe use a perl script for the
name mangling, and call it from the bash script?   :)

anyway, that's my over-valued 2cents. ;)

-G

Gavin McDonald
------------------------
EVI Logistic Enterprises
email: me(at)gavitron(dot)com
phone: (604) 313-3845




More information about the redhat-list mailing list