Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Delete line if date=today

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 07-06-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 3 July 2015, 9:22 AM EDT
Location: Galactic Empire
Posts: 3,409
Thanks: 240
Thanked 1,217 Times in 1,143 Posts
Use grep:

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

Sponsored Links
    #3  
Old Unix and Linux 07-06-2013
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 3 July 2015, 1:17 PM EDT
Posts: 663
Thanks: 34
Thanked 203 Times in 189 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 Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 01:20 PM.