Skip site navigation (1)Skip section navigation (2)
Date:      09 Jan 2003 09:34:22 +1000
From:      Duncan Anker <d.anker@au.darkbluesea.com>
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:  <1042068862.1441.3.camel@duncan.au.darkbluesea.com>
In-Reply-To: <20030108175539.W65616@bigb3server.bbcluster.gr>
References:  <20030108175539.W65616@bigb3server.bbcluster.gr>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 2003-01-09 at 02:01, BigBrother (BigB3) wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> 
> 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?
> 

If you want to do it for all files in a directory:

# for file in *; do mv "$file" `echo $file | sed -e 's/ /_/g'`; done

should do the trick. I think Perl is overkill for something this simple.
Someone else suggested tr, which probably works, but I've had more
success with sed.

cheers,
Duncan

-- 

The information contained in this email is confidential.
If you are not the intended recipient, you may not disclose or use the
information in this email in any way.
Dark Blue Sea does not guarantee the integrity of any emails or attached
files.
The views or opinions expressed are the author's own and may not reflect
the views or opinions of Dark Blue Sea.
Dark Blue Sea does not warrant that any attachments are free from
viruses or other defects.
You assume all liability for any loss, damage or other consequences
which may arise from opening or using the attachments.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1042068862.1441.3.camel>