Filtering log file with lines older than 10 days.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filtering log file with lines older than 10 days.
# 8  
Old 11-02-2017
Linux

Code:
panz:/tmp> awk 'BEGIN {print srand()}'
1
You have new mail in /var/spool/mail/root
panz:/tmp>

# 9  
Old 11-02-2017
OK, there's the error. Try
Code:
awk -vDT=$(date +%s) 'BEGIN {D10 = (DT-864000); split ("OLDER YOUNGER", FN)} {print $0 ">" (FN[1+($2/1E9 > D10)])} ' file

This User Gave Thanks to RudiC For This Post:
# 10  
Old 11-02-2017
Linux

Hi RudiC,

This is throws o/p but does not create a file as expected. This one is awesome. but would you be able to put this o/p in files please. Thank you for all your help.
# 11  
Old 11-02-2017
Sorry, I forgot to remove the "test setup" - remove the double quotes around the redirection operator.
This User Gave Thanks to RudiC For This Post:
# 12  
Old 11-03-2017
SmilieThat works like a champ, Thank you RudiC for your help!!Smilie

---------- Post updated at 09:25 AM ---------- Previous update was at 09:23 AM ----------

Also, I would like to learn more about FN and split part of your script. Please suggest if any documentation.
# 13  
Old 11-03-2017
FN is a variable to hold the file name array used in the "conditional" redirection... For the split command, see man awk and references therein.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To nullify multiple log files older than X days.

Hi, I am writing the script for tomcat logs clean up ending with *.txt and *.log. cleanup should be applied to logs older than 7 days logs same will be scheduled in cron. after googling found below but it only help partially. find . -type f -name '*.log' -exec truncate --size 0 "{}" \; I... (6 Replies)
Discussion started by: Riverstone
6 Replies

2. Shell Programming and Scripting

Search 2 days older file and then delete last 10 lines

I want to search 2 day older file and then delete last 10 line of that file. (2 Replies)
Discussion started by: sonu pandey
2 Replies

3. Shell Programming and Scripting

Remove lines older than 30 days

Hi Experts/Gurus, Is there a way to remove lines in a file that are older than x days (i.e. 30 days) based on the date stamp in the first column? Example. $ date Sat Jan 11 14:12:06 EDT 2014 $cat sample.txt 10-10-2013 09:00:01 AM|Line test 1234567 16-10-2013 08:30:00 AM|Line test... (6 Replies)
Discussion started by: brichigo
6 Replies

4. UNIX for Dummies Questions & Answers

Find all log files under all file systems older than 2 days and zip them

Hi All, Problem Statement:Find all log files under all file systems older than 2 days and zip them. Find all zip files older than 3days and remove them. Also this has to be set under cron. I have a concerns here find . -mtime +2 -iname "*.log" -exec gzip {} Not sure if this will work as... (4 Replies)
Discussion started by: saurabh.mishra
4 Replies

5. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

6. Shell Programming and Scripting

[Solved] Remove file older than 90 days

I have crontab job a tar file to a directory ( tar -cvf /tmp/backup/or.`date +%m%d%y`. /ora/db/* ) , it will do it every day . Now I don't want to keep too much files , I just want to keep the file for 90 days , can advise if I want to remove the backup file which are elder than 90 days , can... (1 Reply)
Discussion started by: ust3
1 Replies

7. Shell Programming and Scripting

Deleting entries older than 7 days from a file

Hi, I have a file which contains entries in this format. my-bin.000140 my-bin.000141 my-bin.000142 my-bin.000143 my-bin.000144 my-bin.000145 my-bin.000146 my-bin.000147 my-bin.000148 my-bin.000149 my-bin.000150 my-bin.000151 my-bin.000152 my-bin.000153 my-bin.000154... (2 Replies)
Discussion started by: arijitsaha
2 Replies

8. UNIX for Dummies Questions & Answers

Delete file older than three days

I am using SFTP to transmit files from the Mainframe to an UNIX server. I am looking for some kind of script that runs with SFTP to delete tranmitted files older than 3 days. Can this be done in a SFTP transmission batch job? (5 Replies)
Discussion started by: Steve Carlson
5 Replies

9. Shell Programming and Scripting

delete file older than N days

Hi, All, I'd like to delete files older than 1 day. I thought the following command find /your_directory -mtime +1-exec rm -f {} \; will do the work, but not so, it seems like it won't delete files unless it is 2 days old or older. the files between 1 day and 2 days old does not... (7 Replies)
Discussion started by: ericaworld
7 Replies

10. UNIX for Advanced & Expert Users

Delete user file(s) older then 'X' days ??

I want to delete any file in unix file system which is older then a week. Those files should not be unix system file..means it should be user created file. Any clue to this ?? ASAP. Thanks. (2 Replies)
Discussion started by: varungupta
2 Replies
Login or Register to Ask a Question