find command returns files with spaces, mv won't work...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find command returns files with spaces, mv won't work...
# 1  
Old 02-26-2009
find command returns files with spaces, mv won't work...

Hi guys.

I am trying, to move files found with the find command...
Script runs fine, until it reaches a file that contains spaces...

Here is what i wrote up quickly.

ROOTDIR=/apps/data
SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-)

for i in $SEARCH

do
echo mv -i $ROOTDIR$i $i
done


In the find, i "cut" the first 19 characters as i can then use it in the mv later one...

I inserted an echo to see the move command prior to executing it...

if i launch the find at the command line, i get this:

/home/tmq/rSIMPL/Mods/Input/bck/2007-12 SEC Balance LOAD #3.csv

But through the script, it comes out like this:

mv -i /home/tmq/rSIMPL/Mods/Input/bck/2007-12 /home/tmq/rSIMPL/Mods/Input/bck/2007-12
mv -i SEC SEC
mv -i Balance Balance
mv -i LOAD LOAD
mv -i #3.csv #3.csv


So my mv -i $ROOTDIR$i $i does not work. I am thinking the variable "i" is getting each entry following a space. How can i get it to "read" the whole line as a whole?

thanks.
# 2  
Old 02-28-2009
Code:
#!/nin/ksh
ROOTDIR=/apps/data
SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-) |
while read i
do
echo mv -i $ROOTDIR"${i}" "${i}"
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux find command returns nothing

Under one of my directories on server I have more than 500 files with different type and name. When I run the find command to list the files with 'ABC_DEFGH' in the begining of its name and older than 20 days, nothing is return as result. Though I know there are more than 400 files which their name... (10 Replies)
Discussion started by: Home
10 Replies

2. AIX

Find and rm files with spaces in the name

I'm sure this has been answered before, but my searches have not turned up the right solution. :confused: I need to remove files in a directory, without descending into subdirectories, older than n days. Some of the filenames contain spaces or other special characters: E10403 (2) E20402 (2)... (15 Replies)
Discussion started by: Papa Lee
15 Replies

3. UNIX for Dummies Questions & Answers

Images won't work?

Hello, Images won't work on UNIX when I try posting them on my website I'm working on. It doesn't show the image, and it's simply erroring. Help! Thanks! (5 Replies)
Discussion started by: yazan
5 Replies

4. BSD

Install cd won't work

Hi! I'm sure that somebody here installed freeBSD from a download of a virtual disc (.iso). But I made 5 downloads of 5 differents freeBSD installation (and no one has worked).Can somebody tell me where to download and how (if needed) to prepare the cd? (8 Replies)
Discussion started by: maxum
8 Replies

5. UNIX for Dummies Questions & Answers

find -size -7M finds files, but won't cp them all

If I run: find /somefolder -type f -size -7M | wc -l I get 73594 files But when I run find /somefolder -type f -size -7M -exec /bin/cp -v {} /someotherfolder/ \; it only copies 38891 of the files to the folder, why? There's a mix of all types of files in /somefolder. Is there some other... (12 Replies)
Discussion started by: unclecameron
12 Replies

6. OS X (Apple)

Why won't the at command work in Mac OS X?

I typed: echo "echo hi > at_log.txt" | at now +1minute to test the at command on my terminal. I got the message: job 8 at Thu Feb 25 18:42:00 2010 I waited for a minute but nothing happened. I tried listing at_log.txt, but it said there was no such file. Am I doing something... (2 Replies)
Discussion started by: Ultrix
2 Replies

7. Shell Programming and Scripting

spaces and carriage returns in 'here documents'

As the title suggests, i am having some trouble figuring out how to pass spaces and carriage returns to a 'here document' ie #!/bin/bash /usr/local/install_script.sh <<SCRIPT yes no <pass carriage retun here> yes no <pass a space and then a carriage return here> exit SCRIPT any... (0 Replies)
Discussion started by: hcclnoodles
0 Replies

8. AIX

does find command always work ?!

hello ! can so help me ? here is my problem : a same command, using find command works on a server, but doesn't on another. I've been told, that it could be because of the file systems ... it's amazing ! can so explain, please ? thank you for your answer (1 Reply)
Discussion started by: chocolate
1 Replies

9. UNIX for Dummies Questions & Answers

why won't this Work?

hey programmers! 1-why won't gcc accept as an argument? i tried the recommendations on the man page of getch(),..etc. nothing worked. 2-why it won't see <iostream> && <fstream> even if i implemented the function as follow std::cout<<"..etc"<<endl; 3-after i type this code in it gives... (6 Replies)
Discussion started by: mbabeli
6 Replies

10. UNIX for Dummies Questions & Answers

cant find command that returns blank line

This is my list of sed commands: can anyone tell me where im going wrong. The script works on a file called data which contains 6 student id's and there answers for 6 questions. !/bin/sh sed -e 's/*//g' \ #replace * with nothing -e s/ /X/g' \ #replacing empty space with X -e... (2 Replies)
Discussion started by: jeffersno1
2 Replies
Login or Register to Ask a Question