On Wed, 8 Jan 2003, BigBrother (BigB3) wrote:

> Sorry for this OT but I am trying for some hours to achieve a massive
> rename of files using a simple script and I have not success yet. I want
> to rename files like
> "RESULTS OF JAN 01 2002.txt "
> to
> "RESULTS_OF_JAN_01_2002.txt"
> i.e. all the spaces, being substituted by '_', and the last space being
> completely removed [yes it has a space after the suffix]
> I tried to experiment with sed/awk and creating a sample sh script with
> for i in 'ls' ....
> but the i takes values of 'RESULTS' 'OF' 'JAN'. This means that it doesnt
> take the full filename as value, but parts of the filenames.
> Can u please suggest an easy way to implement the massive rename?

Maybe something like this?

@ls = `ls`;
chomp @ls;
foreach (@ls) {
        $before = $_;
        if(/\ $/) { chop $_; }
        s/\ /_/g;
        system("mv \"$before\" $_");

This is the kind of question which will come up with hundreds of
solutions from hundreds of persons. :-)

Before using above script you should make a backup first!

Best regards,

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message

Reply via email to