|
|
Rename files in bash via string handling
As evidenced on the other thread, any discussion like this inevitably devolves into an "OK, but here's how <em>I'd</em> do it discussion" -- to which I'm tempted to contribute, but let's set that aside. I'm really interested to discover that bash has these string-editing features. (I'd alwas thought one had to go to Perl for anything more complicated than =~.) Do you know where to look for documentation?
Rename files in bash via string handling
In spite of my comment above, I do regularly use the bash string editing features for other purposes. The resource that I used to learn about these was the O'Reilly book on bash. Of course, that requires the purchase of a book, which is not ideal...and likely not necessary. I'm sure that you can google good web resources.
Rename files in bash via string handling
I can highly recommend the Advanced Bash-Scripting Guide, which is free, and available at http://www.die.net/doc/linux/abs-guide/.
Rename files in bash via string handling
man bash
Rename files in bash via string handling
man bash
Specifically, look for "Parameter Expansion" on the bash man page. (And while you're at it, it's fun to read through the whole man page, to see what else you don't know about!)
Rename files in bash via string handling
Another thing you may wish to look into is using sed. I do a lot of quick renames this way, for example: for i in *.mp3; do mv $i `sed -e "s/^[01][0-9]_/artist--/g"`; done
This would convert files that begin with "##_" (where ## is between 00 and 19) to start with "artist--" instead. Here is a useful and concise guide to regular expressions that I've recommended to other people in the past (which could be used with sed, awk, grep, perl, etc.): http://etext.lib.virginia.edu/services/helpsheets/unix/regex.html |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.13 seconds |
|