need to move find results

I am looking for files of a certian type and logging them. After they are logged they need to be moved to a different directory. HOw can i incorporate that in my current script?

CSV_OUTFILE="somefile.csv"
find . -name W\* -exec printf "%s,%s,OK" {} `date '+%Y%m%d%H%M%S'` \; > ${CSV_OUTFILE}

They would need to be moved from the current directory to one at the same level. For example:

From ./name/inbox/file
To ./name/archive/file

Have you considered using "mv" ?

lol, yeah, let me clarify my question.

How can I apply the mv command to a list of find results?

How about giving us an example of what the CSV output would be....

Hi,

i am not quiet sure about your req.
Suppose it is very close to follow:
Hint: Find all the .txt file in current directory, record them in file.log file and then copy them to the parent directory.

Hope you can finish it according to your exact requirements.

code:

for i in `find . -name \*.txt`
do
	echo $i >> file.log
	cp $i ../	
done

I guess I'd better clarify a bit.

Here is my current script, it formats the output of the find command:

CSV_OUTFILE="somefile.csv"
find . -name W\* -exec printf "%s,%s,OK" {} `date '+%Y%m%d%H%M%S'` \; > ${CSV_OUTFILE}

Now, I need to modify this script to also use the output of the same find command as a list of files that need to be moved.

The CSV file does not need to be moved, later in the script I FTP it to another server where the results are parsed and each time this script is run, it is overwritten anyway.

Hope that explains it better. :wink:

CSV_OUTFILE="somefile.csv"
find . -type f -name W\* \( -exec echo echo {} \> ${CSV_OUTFILE} \; -a -exec echo cp {} /new_dir/ \&\& rm {} \; \) | sh -c

better still...

CSV_OUTFILE="somefile.csv"
find . -type f -name W\* \( -exec echo {} \; > ${CSV_OUTFILE} -a -exec cp {} /new_dir/ \; -exec rm {} \; \)

Thank you shamrock! I tweaked it a bit for my environment and it works perfectly now. :slight_smile:

Put in place the lost "-a" operator for combining the last 2 "-exec". It most likely got lost in the copy & paste operation. You can tweak it for your environment...:slight_smile:

CSV_OUTFILE="somefile.csv"
find . -type f -name W\* \( -exec echo {} \; > ${CSV_OUTFILE} -a -exec cp {} /new_dir/ \; -a -exec rm {} \; \)

[/quote]