Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Rename files in bash via string handling' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Rename files in bash via string handling
Authored by: JadeNB on Sep 07, '06 09:11:01AM

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?



[ Reply to This | # ]
Rename files in bash via string handling
Authored by: riceran on Sep 07, '06 09:22:39AM

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.



[ Reply to This | # ]
Rename files in bash via string handling
Authored by: barefootguru on Sep 07, '06 02:42:02PM
I can highly recommend the Advanced Bash-Scripting Guide, which is free, and available at http://www.die.net/doc/linux/abs-guide/.

[ Reply to This | # ]
Rename files in bash via string handling
Authored by: -dl- on Sep 07, '06 09:30:18AM

man bash



[ Reply to This | # ]
Rename files in bash via string handling
Authored by: lihtox on Sep 07, '06 12:31:24PM
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!)

[ Reply to This | # ]

Rename files in bash via string handling
Authored by: MordEth on Sep 07, '06 10:31:46AM

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



[ Reply to This | # ]