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
print as well as count the files found by find command amicon007 Shell Programming and Scripting 3 02-05-2009 12:38 PM
find command in while loop - how to get control when no files found? mavsman Shell Programming and Scripting 3 04-03-2008 12:44 PM
Files in Lost+Found spricks UNIX for Dummies Questions & Answers 1 02-05-2008 11:26 AM
Monitoring a directory for new files with .xx and executing command if found krkan Shell Programming and Scripting 4 03-14-2006 11:16 PM
variable not found with loop? douknownam Shell Programming and Scripting 2 09-27-2004 11:59 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 04-22-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

Quote variable references:

Code:
mv -i "$file" `echo "$file" | sed 's/ //g'`
  #2 (permalink)  
Old 04-22-2009
abinaya abinaya is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 24
hi,

did u try the code given by me ?
  #3 (permalink)  
Old 04-22-2009
Calypso Calypso is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 29
@abinaya
sorry, yes i did try your solution and im afraid i couldnt get it to work either

These are two methods which are very close but still dont work, any other ideas
Code:
#method1
find $dir -name "* *" | while IFS= read -r file; do
echo "$file remove spaces (Y/N)"
read opt
case $opt in
[yY])  mv -i "$file" `echo "$file" | sed 's/ //g'`;;
[nN])  ;;
*) echo "input not regonised";;
  esac
done
this script does not wait for the user input example output looks like
spaceDir/ 234.txt remove space (Y/N)
input not regonised
spaceDir/12 34.txt remove space (Y/N)
input not regonised

Code:
method 2
for file in `find $dir -name "* *"`; do
 printf "%s: remove spaces(Y/N): " "$file"
  read opt
  case $opt in
    [yY])  mv -i "$file" `echo "$file" | sed 's/ //g'`;;
    [nN])  ;;
    *) echo "input not regonised";;
  esac
done
This method waits for the user input but does not print out the file correctly e.g
spaceDir/file remove spaces(Y/N): y
mv: cannot access spaceDir/file
spaceDir/name remove spaces(Y/N): y
mv: cannot access spaceDir/name

Thanks in advance
  #4 (permalink)  
Old 04-22-2009
abinaya abinaya is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 24
Hi,

I have created few files with spave in between.My code works as follows.

# more test1
#!/bin/sh
for file in *.txt
do
echo " \"$file\" delete(Y/N) :"
read opt
case $opt in
[yY])rm "$file"
echo "$file removed........."
;;
esac
done
# touch "1 .txt" "2 .txt"
# touch "4.txt" "_3.txt"
# ls *.txt
1 .txt 2 .txt _3.txt 4.txt
# ./test1
"1 .txt" delete(Y/N) :
y
1 .txt removed.........
"2 .txt" delete(Y/N) :
y
2 .txt removed.........
"4.txt" delete(Y/N) :
y
4.txt removed.........
"_3.txt" delete(Y/N) :
y
_3.txt removed.........
# ls -l *.txt
*.txt: No such file or directory
#
  #5 (permalink)  
Old 04-22-2009
Calypso Calypso is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 29
Thanks abinaya, very useful
Calypso
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 11:09 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