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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
11-29-2004, 03:26 PM
|
#1
|
|
LQ Newbie
Registered: Nov 2004
Posts: 3
Rep:
|
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...
|
|
|
|
11-29-2004, 03:28 PM
|
#2
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
Welcome to LQ.
You could use something like this:
Code:
if [ `grep -c "string" $file` -gt 0 ];then
rm -f $file
fi
|
|
|
|
11-29-2004, 03:59 PM
|
#3
|
root 
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 9,588
|
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
--jeremy
|
|
|
|
11-30-2004, 03:31 PM
|
#4
|
|
LQ Newbie
Registered: Nov 2004
Posts: 3
Original Poster
Rep:
|
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
|
|
|
|
12-01-2004, 01:23 PM
|
#5
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
I have no idea how you will do it. How is the script going to be called?
|
|
|
|
12-02-2004, 01:20 PM
|
#6
|
|
LQ Newbie
Registered: Nov 2004
Posts: 3
Original Poster
Rep:
|
I would run the script manually or put it in cron.
|
|
|
|
12-02-2004, 01:54 PM
|
#7
|
|
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:14 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|