Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing unwanted file, help pls ... 1

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys,

I have many files coming everyday, and I have a list of files that want.

So, I need to check the files coming whether they are in the list or not. If not, I have to remove it.

so in pseudo code would be like this :
find $dest_dir -name "*.csv" > incoming_file_list.txt

for file in `cat incoming_file_list.txt`
do
check whether the file is in the wanted_list.txt
if not
remove it
done

How do I code it ?

Thanks guys






 
Something like this?

Code:
find $dest_dir -name "*.csv" > incoming_file_list.txt  

rm `diff incoming_file_list.txt wanted_list.txt |grep -v ">" |awk '{ print $2 '}`
Just make sure the "wanted_list.txt" conforms EXACTLY to the output you get from your "find" command. Otherwise you'll be removing nearly everything (recursively) in the directory. Trade the "rm" above with a "file" or "ls" until you get the results you want.
As further explaination, my first run didn't include the leading ./ in the "wanted_list.txt" file and I accidentally removed everything ending in ".csv".

There are probably safer ways to do this.


"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Thx for the idea man,

I thought I have to check the files one by one in the list.

Cheers,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top