LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-29-2004, 04:26 PM   #1
road69runners
LQ Newbie
 
Registered: Nov 2004
Posts: 3

Rep: Reputation: 0
filtering a file then deleting it.


How do I filter a file for a certain string, and, if it is found delete the file and a binary file asscoiated with it? Example: I have several mail files that get bounced back due to bad addrersses. I want to delete these files and the binary file that is assciated with it. The binary file has the same name but starts with a "d". Any help would be greatly appreciated as I am a novice with perl, awk, sed and the rest of the commands. Thanks...
 
Old 11-29-2004, 04:28 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Welcome to LQ.

You could use something like this:
Code:
if [ `grep -c "string" $file` -gt 0 ];then
 rm -f $file
fi
 
Old 11-29-2004, 04:59 PM   #3
jeremy
root
 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 10,479

Rep: Reputation: 2635Reputation: 2635Reputation: 2635Reputation: 2635Reputation: 2635Reputation: 2635Reputation: 2635Reputation: 2635Reputation: 2635Reputation: 2635Reputation: 2635
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

--jeremy
 
Old 11-30-2004, 04:31 PM   #4
road69runners
LQ Newbie
 
Registered: Nov 2004
Posts: 3

Original Poster
Rep: Reputation: 0
David,
Thanks for the info...but being the newbie I am not sure what to do with it. Can I use this in a shell script? How do I read the file in when the file name will be different each time? And how do I delete the associated binary file that has the same name but with a "d" in front of it?
Sorry for all the questions. Someday I hope to learn all of this.
Thanks again for the help.....Rick
 
Old 12-01-2004, 02:23 PM   #5
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
I have no idea how you will do it. How is the script going to be called?
 
Old 12-02-2004, 02:20 PM   #6
road69runners
LQ Newbie
 
Registered: Nov 2004
Posts: 3

Original Poster
Rep: Reputation: 0
I would run the script manually or put it in cron.
 
Old 12-02-2004, 02:54 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Then call the script like:
/path/to/script /path/to/file_to_check

Code:
#!/bin/bash
file=$1
if [ `grep -c "string" $file` -gt 0 ];then
 rm -f $file
fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering a file (taking paths) kornerr Programming 4 05-15-2005 10:22 AM
Deleting a file starting with a ? bitpicker Linux - General 6 11-24-2004 02:20 PM
deleting a file intellscreen Linux - Newbie 3 11-02-2003 01:39 PM
Sendmail Spam filtering and Virus filtering MrJoshua Linux - General 2 04-03-2003 11:12 AM
Deleting a file...... lucifer Linux - Software 0 09-03-2002 04:36 AM


All times are GMT -5. The time now is 12:27 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration