Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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)

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?

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"$(

...nope, that's even worse. Trying again...
Mass-destruction version:
rm $(
Line-by-line version: for f in $(
do
print rm $f
done"$(

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

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"$(

![]() |
![]() |
![]() |

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