Computing.Net > Forums > Unix > Remove files from list

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Remove files from list

Reply to Message Icon

Name: Mats Bengtsson
Date: March 25, 2003 at 01:36:07 Pacific
OS: Solaris 8
CPU/Ram: Ultra Sparc/512 MB
Comment:

Hi,

I would like to delete the files in the list below. The file list is over 5000 lines long.
It looks something like this:
test.12001
test.12002
test.12003
...

I would like to remove all these testfiles with a script. How can I do this?

BR
Mats



Sponsored Link
Ads by Google

Response Number 1
Name: Jimbo
Date: March 25, 2003 at 02:52:06 Pacific
Reply:

Using sed, you could do something like:

#! /bin/sh
sed '/^test\.[0-9]\{5\}$/d' file > file.new
mv file.new file


This removes a string that begins with 'test', followed by a literal period, followed by 5 numbers at the end of a line.

-jim


0

Response Number 2
Name: WilliamRobertson
Date: March 25, 2003 at 05:38:46 Pacific
Reply:

Or if you meant you want to feed the 5000 filenames into an 'rm' command (i.e. delete the 5000 files listed), try:

rm $( deletethese.dat)

Make sure that is what you want to do first though - rm can be a weapon of mass destruction.

A less efficient bit more flexible approach would be to read each line:

for f in $(deletethese.dat)
do
print rm $f
done

(remove the 'print' above to actually delete the files)


0

Response Number 3
Name: Mats Bengtsson
Date: March 26, 2003 at 07:15:48 Pacific
Reply:

Hi,

I tried your little script above on my file but i didn't remove the files that were in the list.
Do I need to run it in any shell (ksh, bash)?
What permissions should have on the file that contains the list of files?

How can I see if there is a problem with the script?


0

Response Number 4
Name: WilliamRobertson
Date: March 26, 2003 at 07:30:15 Pacific
Reply:

Apologies, the less-than symbols got lost in posting. That should have been:

Mass-destruction version:

rm $(Line-by-line version:

for f in $(do
print rm $f
done

"$(


0

Response Number 5
Name: WilliamRobertson
Date: March 26, 2003 at 07:31:56 Pacific
Reply:

...nope, that's even worse. Trying again...

Mass-destruction version:

rm $(Line-by-line version:

for f in $(do
print rm $f
done

"$(


0

Related Posts

See More



Response Number 6
Name: WilliamRobertson
Date: March 26, 2003 at 07:37:12 Pacific
Reply:

You know, some days I get this to work without any problems (using HTML '<')...

That was supposed to show
rm $(less-than deletethese.dat)

and

for f in $(less-than deletethese.dat)
do
print rm $f
done


0

Response Number 7
Name: Mats Bengtsson
Date: March 26, 2003 at 07:39:57 Pacific
Reply:

I'm sorry, but what do you mean with this.
There are no less-than symbols here only () sybols.

for f in $(do
print rm $f
done

"$(



0

Response Number 8
Name: Mats Bengtsson
Date: March 26, 2003 at 07:42:30 Pacific
Reply:

OK,

Thank you!!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Remove files from list

Remove old files from Dir > 60 days www.computing.net/answers/unix/remove-old-files-from-dir-60-days/7847.html

deleting files from a tarfile www.computing.net/answers/unix/deleting-files-from-a-tarfile/3313.html

remove ^M from a file www.computing.net/answers/unix/remove-m-from-a-file/7537.html