Remove content from file | 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.

Remove content from file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-30-2006
mpang_ mpang_ is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 16 November 2008, 8:20 PM EST
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
Remove content from file

hey all, I have a file with records in following format

8-29-2006 13:01:45|ABC|45
8-29-2006 14:23:12|DEF|21
8-30-2006 00:04:57|ABC|34

I want to remove all yesterday records. Can anyone show me how? Thanks!
Sponsored Links
    #2  
Old 08-30-2006
jambesh's Avatar
jambesh jambesh is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 29 March 2012, 1:48 AM EDT
Location: California,USA
Posts: 153
Thanks: 0
Thanked 0 Times in 0 Posts
Do you mean you want to keep the today's record and removed all the past record ??
or you want to remove only the yester day record keeping all prior record and today's record intact.?
Sponsored Links
    #3  
Old 08-30-2006
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
 
Join Date: Feb 2006
Last Activity: 6 October 2014, 10:13 AM EDT
Location: Almerķa, Spain
Posts: 777
Thanks: 24
Thanked 110 Times in 105 Posts
Perl solution:

Code:
perl -i.old -ne 'print unless /^8-29/' file

    #4  
Old 08-30-2006
mpang_ mpang_ is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 16 November 2008, 8:20 PM EST
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
This is supposed to be a daily job, so if I am doing the right job from the beginning then all I need to do should be removing yesterday record. But I guess only keeping today's record and removed all the past reocrds should do as well. Thanks
Sponsored Links
    #5  
Old 08-30-2006
jambesh's Avatar
jambesh jambesh is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 29 March 2012, 1:48 AM EDT
Location: California,USA
Posts: 153
Thanks: 0
Thanked 0 Times in 0 Posts
what my approach is

today=`date '+%m-%d-Y'`
grep -v "$today" file_name >file_name

Last edited by jambesh; 08-31-2006 at 04:27 AM.. Reason: update
Sponsored Links
    #6  
Old 08-30-2006
mpang_ mpang_ is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 16 November 2008, 8:20 PM EST
Posts: 89
Thanks: 0
Thanked 0 Times in 0 Posts
the problem is I can only modify the file, writing the entries to another file is not an option. Can anyone help?
Sponsored Links
    #7  
Old 08-31-2006
jambesh's Avatar
jambesh jambesh is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 29 March 2012, 1:48 AM EDT
Location: California,USA
Posts: 153
Thanks: 0
Thanked 0 Times in 0 Posts
you can do that if you redirect the out put to the same file , but here you will lose the original file information , i mean the same file will contain the todays log only previous log will be removed .
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
Help with remove duplicated content perl_beginner Shell Programming and Scripting 3 08-22-2011 10:35 AM
Shell script to remove some content in a file Mr_47 Shell Programming and Scripting 4 08-11-2011 03:59 AM
Help with remove duplicate content and only keep the first content detail patrick87 Shell Programming and Scripting 9 12-20-2010 09:17 AM
Remove specific content in a file k9cheung Shell Programming and Scripting 1 08-10-2009 03:37 PM
remove space from file content blackzinga Shell Programming and Scripting 4 06-01-2009 10:02 AM



All times are GMT -4. The time now is 06:18 AM.