Date: Wed, 8 Jan 2003 17:38:49 +0100 (MET) From: Paul Everlund <tdv94ped@cs.umu.se> To: "BigBrother (BigB3)" <bigbrother@bonbon.net> Cc: freebsd-questions@freebsd.org Subject: Re: Renaming files with spaces in the name to files without spaces.. Message-ID: <Pine.GSO.4.44.0301081736310.28524-100000@kvist.cs.umu.se> In-Reply-To: <20030108175539.W65616@bigb3server.bbcluster.gr>
index | next in thread | previous in thread | raw e-mail
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?
#!/usr/bin/perl
@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,
Paul
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.44.0301081736310.28524-100000>
