converting spaces to underscores

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 18 Sep 2001, Nicolas Pitre wrote:
 > On Tue, 18 Sep 2001, Thomas Stivers wrote:
 > 
 > > I have recently gotten linux up and running and I am becoming really
 > > frustrated with the filenames I created in windows which have spaces in
 > > them.
 > 
 > Quote them like "foo bar" and you should be able to use those filenames as
 > well.
while true (and most shells will do that for you or escape them), it miht
sometiems be handi to indeed remove them

Here's a script that will do so:
#!/bin/bash
list=`ls *`

for l in $list
do mv $l `echo $l | awk 'BEGIN{RS=" ";ORS="_";}{print $1}' | \
   sed s/.$//`
done

note:
1. run this script in the directory you want to rename files in
2. first edit it and change "mv" into "echo" to see if it does what you
really wnat (and expect it) to do
3. change it back and execute it

This script comes with no warantee wahtsoever, use at your own risk!


 > 
 > Nicolas
 > 
 > 
 > 
 > _______________________________________________
 > 
 > Blinux-list@redhat.com
 > https://listman.redhat.com/mailman/listinfo/blinux-list
 > 

slainte mhaith (good health), slainte (cheers)
Uisce Beatha (water of live/health)
-----------
Andor Demarteau                 E-mail: ademarte@students.cs.uu.nl
student computer science        www: http://www.students.cs.uu.nl/~ademarte/
Utrecht University              irc: see webpage for details
-----------
Believe in yourself, know what you want, and make it happen!





[Index of Archives]     [Linux Speakup]     [Fedora]     [Linux Kernel]     [Yosemite News]     [Big List of Linux Books]