Moderators: ChriThor, LXF moderators
johnlane wrote:One way to sort your file names out is to use EasyTag. See my piece in LXF171.
IFS='
'
for x in *.mp3 ; do y=`echo $x | cut -d"-" -f 2- | sed "s/^_//g" `; mv -v "$x" "$y" ; done
MartyBartfast wrote:This would do it, assuming that the delimiter between the bits you do want and the bits you don't want is always a hyphen "-".
- Code: Select all
IFS='
'
for x in *.mp3 ; do y=`echo $x | cut -d"-" -f 2- | sed "s/^_//g" `; mv -v "$x" "$y" ; done
The IFS and the following line are in case some files have a space in their name, it will set the field separator to newline only (not required if there are no files with spaces).
for dirname in find /amazonmp3 -type d ; do cd $dirname ; for x in *.mp3 ; do y=`echo $x | cut -d"-" -f 2- | sed "s/^_//g" `; echo mv -v "$x" "$y" ; done ; done
MartyBartfast wrote:Off the top of my head try
- Code: Select all
for dirname in find /amazonmp3 -type d ; do cd $dirname ; for x in *.mp3 ; do y=`echo $x | cut -d"-" -f 2- | sed "s/^_//g" `; echo mv -v "$x" "$y" ; done ; done
note I've changed the command to 'echo mv -v "$x" "$y" ' that way you can run it and it will just display what it's going to do, if everything looks good just remove the "echo" and run it and it will do the job.
It would probably be neater and more maintainable to stick this in a shell script and indent it properly, particularly if it's going to get any more complex.
for dirname in find /amazonmp3 -type d
do
cd $dirname
for x in *.mp3
do
y=`echo $x | cut -d"-" -f 2- | sed "s/^_//g" `
echo mv -v "$x" "$y"
done
done
rename -R -t -s/.\*__//r /amazommp3
nelz wrote:If you want easier to read, replace the backticks with $().
But the whole thing is much easier with a dedicated command, like rename. If you want to remove everything up to and including the first double underscore
- Code: Select all
rename -R -t -s/.\*__//r /amazommp3
The -t option shows the renames without performing them. Remove this, or replace it with -v, to do it for real.
nelz wrote:That's the rename command I mentioned earlier in this thread, not the one from coreutils.
rename.c:68:6: error: #elif with no expression
#elif
^
// Original code.
#if HAVE_REGEX_H
#include <regex.h>
#elif
#include "regex.h"
#endif
#if HAVE_REGEX_H
#include <regex.h>
#else
#include "regex.h"
#endif
Users browsing this forum: No registered users and 1 guest