LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 04-16-2008, 12:48 AM   #1
nishanthhampali
LQ Newbie
 
Registered: Apr 2008
Posts: 1

Rep: Reputation: 0
How to delete the file using pattern match?


hello all,
I have a folder which contains the file name in the format
date_hostname_instance.log For eg:20080416_blrm1548_instance1.log

In the folder i have to check for the file name which starts with the current date and delete it(using shell script).

Please let me know your views on this
 
Old 04-16-2008, 03:06 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
rm $(date +%Y%m%d)_blrm*.log
 
Old 04-16-2008, 08:21 AM   #3
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
If the hostname is dynamic, then you can use.
Code:
rm "$(date +%Y%m%d)_$HOSTNAME*.log"
 
Old 04-16-2008, 12:50 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by angrybanana View Post
If the hostname is dynamic, then you can use.
Code:
rm "$(date +%Y%m%d)_$HOSTNAME*.log"
Except remove the double quotes.
 
  


Reply



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
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
delete file that match the content packets Programming 5 04-03-2007 02:47 PM
how to use the sed w option to redirect pattern match to file nickleus Linux - General 11 04-18-2006 08:34 AM
perl pattern match question lluciano Programming 4 02-28-2006 05:59 AM
svcadm: Pattern 'apache' doesn't match any instances xpucto Solaris / OpenSolaris 8 02-19-2006 07:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:41 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration