Results 1 to 8 of 8
Greetings!
I have a dir with 10,000 text files and growing. Do you have a script where if the word "LINUXFORUMS" has on the body of the text file, it ...
- 04-03-2007 #1Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
how to delete file with matching content
Greetings!
I have a dir with 10,000 text files and growing. Do you have a script where if the word "LINUXFORUMS" has on the body of the text file, it will automatically delete the file. I cannot get to it since I'm only familiar to BASH. Anyone have a script similar to this or any ideas how can i do this? Any links where it can direct me to this kind of script?
TIA
--linux newbie
- 04-03-2007 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
since you know bash, what have you done so far? a simple eg
Code:for file in * do grep "LINUXFORUMS" file > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "Removing file $file" ## enter remove code here. fi done
- 04-03-2007 #3Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
thanks for the idea. I will try these one.
Anymore suggestions?
- 04-03-2007 #4
try this...
Try this...
add -i for searching case-insensitive.Code:grep -rl 'some text' /path/to/dir | xargs -d '\n' rm
Code:grep -rli 'some text' /path/to/dir | xargs -d '\n' rm
Hope this help.
- 04-03-2007 #5Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
Anyone could help me on this? This a sample dunno if works
#!/bin/bash
dir=/home/user/dir
echo "Type word:"
read input
if [ $input -eq "LINUXFORUM" ]
then
grep $input $dir
! -------> This is where I want to delete the file when a word "LINUXFORUM"
has match on of the content of the file.
fi
- 04-03-2007 #6Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
@Suseholic
Thanks again for the idea. I think this is a good one. I'll check on this and create a simple script and post it here
- 04-03-2007 #7Linux Newbie
- Join Date
- Mar 2006
- Posts
- 101
This one did a trick. Thanks!
#!/bin/bash
echo "Please choose user:"
read input1
echo "Type a word.All spam contain this word will be deleted"
read input2
grep -rl $input2 /home/$input1/Maildir/.junkmail/new | xargs -d '\n' rm
- 04-03-2007 #8


Reply With Quote