Delete line if date=today | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Delete line if date=today

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-06-2013
p.carter p.carter is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 24 July 2013, 3:56 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Delete line if date=today

Hi,

I'm trying to write a script that looks at a file, and if the date (dd/mm/yyyy) equals today's date, then delete the line.
I've tried passed the date into sed, but no success.

Any help would be much appreciated.

Phillip
Sponsored Links
    #2  
Old 07-06-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 October 2014, 8:12 PM EDT
Location: Galactic Empire
Posts: 3,387
Thanks: 235
Thanked 1,209 Times in 1,135 Posts
Use grep:

Code:
grep -v "$(date +%d/%m/%Y)" file

Sponsored Links
    #3  
Old 07-06-2013
Aia's Avatar
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 26 October 2014, 1:50 AM EDT
Posts: 468
Thanks: 32
Thanked 151 Times in 142 Posts
Quote:
Originally Posted by p.carter View Post
Hi,

I'm trying to write a script that looks at a file, and if the date (dd/mm/yyyy) equals today's date, then delete the line.
I've tried passed the date into sed, but no success.
[...]
The `/' in the format of your variable, most likely, is messing your command up.

Try:
(escaping the /)

Code:
today=`date "+%d\/%m\/%Y"`
sed /$today/d file


Last edited by Aia; 07-06-2013 at 03:04 PM.. Reason: Minor grammar correction.
    #4  
Old 07-06-2013
p.carter p.carter is offline
Registered User
 
Join Date: Jul 2013
Last Activity: 24 July 2013, 3:56 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Yoda, Aia! Both solutions work.

Phillip
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
UNIX date fuction - how to deduct days from today's date juzz4fun Shell Programming and Scripting 4 05-23-2013 02:31 PM
[Solved] Replace yesterday date with today's date except from the first line Lilu_CK Shell Programming and Scripting 3 12-03-2012 01:44 PM
Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete citizencro UNIX for Dummies Questions & Answers 3 04-11-2011 09:03 PM
Delete lines in a file by date on the line fas1 Shell Programming and Scripting 5 01-21-2011 08:51 AM
compare today's date with date in a file siog UNIX for Dummies Questions & Answers 4 10-04-2006 11:55 AM



All times are GMT -4. The time now is 03:43 AM.