The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace NULL with space pukars4u UNIX for Dummies Questions & Answers 1 06-22-2008 06:15 AM
replace space with new line dakid Shell Programming and Scripting 2 06-03-2008 09:47 PM
How can i replace a character with blank space? rollthecoin AIX 8 04-22-2008 09:55 AM
Replace , (comma) with space mbarberis Shell Programming and Scripting 6 03-29-2005 11:35 AM
replace tab with space avnerht UNIX Desktop for Dummies Questions & Answers 1 06-13-2002 08:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-21-2009
ruben.rodrigues ruben.rodrigues is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 45
replace space by _

Hi

I need to know how I change the spaces by _ in folders and filder founded by find

ex.

find . -name "* *" -exec echo {} \;

./test space
./test space/new file.txt
./test space/new file
./test space/untitled folder
./test space/untitled folder/new fileruben
./Backup/backup/Image for linux Key
./Backup/backup/dings/Backup tool
./Backup/backup/dings/backup reading diff.sh

which option should I exec??

thanks
  #2 (permalink)  
Old 01-21-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,326
Try it first without the coloured part to insure the commands are correct:


Code:
find . -name "* *" -exec echo {} \; |
sed 's/\(.*\) \(.*\)/mv & \1_\2/' | sh

Regards
  #3 (permalink)  
Old 01-21-2009
ruben.rodrigues ruben.rodrigues is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 45
Hi

thanks a lot for you script but something strange is happaning. The verbose is correct but nothing happens.
It say mv ./new file.txt ./new_file.txt (which is correct) but then it stills the same, even with sudo

and the couloured part gives error

Any idea? thanks a lot
  #4 (permalink)  
Old 01-21-2009
ruben.rodrigues ruben.rodrigues is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 45
hmm I know why

I have to do mv ./new\ file.txt ./new_file.txt

with the \ in the space
I think that I can first echo to a file then in the file take the spaces and then use the file to change the space by a _
Do you think it's possible?
  #5 (permalink)  
Old 01-21-2009
palanisvr palanisvr is offline
Registered User
  
 

Join Date: Mar 2007
Location: India
Posts: 16
try this ...

this might work ...but u may need to change it accordingly



for i in `find . -name "*" `
do

fil_path=`echo $i|tr -s |tr ' ' '_'`|tr '\' '_'

echo fil_path : $fil_path

mv $i $fil_path

done
  #6 (permalink)  
Old 01-21-2009
palanisvr palanisvr is offline
Registered User
  
 

Join Date: Mar 2007
Location: India
Posts: 16
Try this ...

As i dont have unix machine i havent verified the code in the machine ,
so i suggest you to test code no 1 , if it works then you can proceed with code no 2
#=========
#Code No : 1
#==========

for i in `find . -name "*" `
do
fil_path=`echo $i|tr -s |tr ' ' '_'`
echo New fil_path : $fil_path
done


#=========
#Code No : 2
#==========
for i in `find . -name "*" `
do
fil_path=`echo $i|tr -s |tr ' ' '_'`
echo fil_path : $fil_path

mv $i $fil_path

done


I hope it works ...........
  #7 (permalink)  
Old 01-21-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,130

Code:
find . -name "* *" -exec echo {} \; | sed 's/\(.*\) \(.*\)/mv "&" "\1_\2/"' | sh

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0