Operating System - Linux
1748134 Members
3353 Online
108758 Solutions
New Discussion юеВ

Re: perl help/excel/delete

 
SOLVED
Go to solution
Shaf_1
Advisor

perl help/excel/delete

I have over 4000k .pdf files that I need to filter for the right type (i.e. Personal, Business, Notes, Report). I have an excel file that lists all the file names and the associated type. What I am trying to do is get all the files that are type тАШNotesтАЩ and тАШPersonalтАЩ and delete the others. Once I have types тАШNotesтАЩ and тАШPersonalтАЩ from that bunch I want to randomly select (and cut) 1000 files and put them in a new folder. Can this be done using perl?
19 REPLIES 19
Steven E. Protter
Exalted Contributor
Solution

Re: perl help/excel/delete

use cut and paste and vi to create a simple filelist, one line per file.

put the file inot Linux(we are in linuxland).

while read -r filename
do
rm -f $filename
done < filelist

That will nuke them all and fast.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Shaf_1
Advisor

Re: perl help/excel/delete

Do I have to assign the file name path? I am guessing this is a shell script that you told me to write.
Michael Schulte zur Sur
Honored Contributor

Re: perl help/excel/delete

Hi,

Sep said to cut and paste the filenames fro your excel sheet and create a file with it then create the script he posted and let it run in the same dir as your filelist. If you do only have relative filenames than you will have to put both files at the top of your filenames path.

greetings,

Michael
Shaf_1
Advisor

Re: perl help/excel/delete

I tried using the script you told me however I keep getting an error. The error is:

"while: Expression Syntax".

The code I am using is:

#!/bin/csh
while read -r newset
do
rm -f $newset
done < filelist


What am I doing wrong?

Stuart Browne
Honored Contributor

Re: perl help/excel/delete

Steven's example was a bash/sh/ksh example, not a csh example. the language is different.

Change the #!/bin/csh to just #!/bin/sh
One long-haired git at your service...
Shaf_1
Advisor

Re: perl help/excel/delete

That worked just great.

I have another question. From my new list of files I want to select 1000 random files.
How would I select the 1000 random files and delete them from the current folder and put them in another folder?
Michael Schulte zur Sur
Honored Contributor

Re: perl help/excel/delete

Hi,

what do mean by random?
You can select with CTRL+mouseclick and number of files in your excel sheet, create the filelist and use mv instead of rm in the script.

greetings,

Michael
Shaf_1
Advisor

Re: perl help/excel/delete

I wanted to know if there is a way to select the files at random by having the computer select the files. I have 1000 files I need to select.
Michael Schulte zur Sur
Honored Contributor

Re: perl help/excel/delete

Hi,

from what source and according to what criteria is the computer to select the files?

greetings,

Michael