Grep file containing dates


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Grep file containing dates

How to grep a file containing dates to only last 30 days then move to another folder
# 2  
Welcome kmarcus,

It sort of seems like a question that has been asked before in many different ways, but in order for us to help, you would need to show us some sample data to include/exclude.

Additionally, when you say "then move to another folder", which of these do you mean? :-
  • move the whole files that contain a recent or old date
  • extract the matching records to a separate file and move that
  • extract the matching records (removing from the original file) to a new file and move that
  • something else?

I have a few general to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.



Kind regards, and hoping to help,
Robin
These 2 Users Gave Thanks to rbatte1 For This Post:
# 3  
Code:
$ awk '$NF < "2018-05-01"' ip.txt

hello I am using Unix the script I am looking for should automatically pick the date from the system current date rather than manually typing the date and move text lines containing lines older than 30 days to another folder say myname.dat
# 4  
Hi Kmarcus,

You'll need to be a little more specific, please look at rbattle1's reply to your post and provide us with as much of the information as you can.

There are many members here who will be able to assist you, however you have to enable us to assist by providing us with the information we need to assist you in solving your problem.

Regards

Gull04
This User Gave Thanks to gull04 For This Post:
# 5  
grep is a program, not a verb -- a program that does exactly what you do not want. It is almost never a useful descriptive term.
# 6  
Most linux distributions have dgrep available - date grep. Primarily, it uses the standard library to convert dates to number of seconds since Jan 1, 1970.
Then dgrep does what grep does with the transformed date - select lines from a file

dgrep linux command man page
This User Gave Thanks to jim mcnamara For This Post:
# 7  
Code:
awk -v t=$(date +%Y-%m-%d) -F "'" '$1 < t' myname.dat

I have the above unix command to filter text with dates older than the current date on unix HP-UX
how can I modify it to filter dates 30 days older than the current date such as 30 days ago without getting the date: illegal option error




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-20-2018 at 05:17 PM.. Reason: Added CODE tags.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Mathematics
Difficulty: Medium
The Pythagorean theorem states that the square of the hypotenuse is equal to the product of the squares of the other two sides.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to get the Missing dates between two dates in the table?

Hi Am Using Unix Ksh ... I have a Table called date select * from date ; Date 01/02/2013 06/02/2013 I need the output as Missing Date 01/02/2013 02/02/2013 03/02/2013 04/02/2013 05/02/2013 06/02/2013 (2 Replies)
Discussion started by: Venkatesh1
2 Replies

2. Shell Programming and Scripting

Grep search for value between dates

Hi I am new to scripting and I have a requirement to grep a value from large numbers of xml files and see if this value exist then I want to check the date and see if it falls between two dates (eg: today and feb 17), then print the name of file. the values in xml file is as follow... (7 Replies)
Discussion started by: mmsiddig
7 Replies

3. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

4. Shell Programming and Scripting

How to processing the log file within certain dates based on the file name

Hi I am working on the script parsing specific message "TEST" from multiple file. The log file name looks like: N3.2009-11-26-03-05-02.console.log.tar.gz N4.2009-11-29-00-25-03.console.log.tar.gz N6.2009-12-01-10-05-02.console.log.tar.gz I am using the following command: zgrep -a --text... (1 Reply)
Discussion started by: shyork2001
1 Replies

5. UNIX for Dummies Questions & Answers

Extract dates from file name.

Hi All, I have files with names as us_Gec1_wk_01to01_2008.TXT ad_EngEnt_wk_01to10_2008.TXT br_EngMov_wk_01to10_2008.TXT Over here, I need to extract the dates and the year and store them in variables. How can I achieve the same in bash. In case of ad_EngEnt_wk_01to10_2008.TXT ... (3 Replies)
Discussion started by: Swapna173
3 Replies

6. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

7. Shell Programming and Scripting

Help to switch dates from a file

Hi. I need some assistance with a file who at the end i must import to EXCEL. The problem is that i have a file with this inside: Output: JOBID START TIME END TIME ELAPSED CPU ------------------------------------------------------------ AVERAGE: ... (2 Replies)
Discussion started by: osramos
2 Replies

8. Shell Programming and Scripting

grep a log file to filter previous dates

Hi, I have problem of filtering a log file from my perl script. #cat /data/pinpe.csv_20070731 | nawk -v FS=, '{print $1','$18','$22','$26}' | grep -w 100 | grep -w 1 | nawk '{print $4}' Below is the output: 2009-06-16 2009-01-29 2009-06-02 2008-03-05 2007-08-05 2007-09-24... (5 Replies)
Discussion started by: pinpe
5 Replies

9. Shell Programming and Scripting

grep a log file between 2 dates

Hi Currently I can grep a log file with the following command: $results = `grep -A 2 '^$date.$time.*' $log`; and the following arguments: $date = 2007/04/25 $time = 16:07 Log example: 2007/04/25 16:07:12.145701 2007/05/25 14:07:12.145701 2007/05/25 17:07:12.145701 2007/06/25... (37 Replies)
Discussion started by: Epiphone
37 Replies

10. UNIX for Dummies Questions & Answers

Formatting dates in a file

Hi! Sitting with a headache this morning and can't get the brain around it! I have a file with 32000 lines that needs to be inserted onto a database. My problem is with the following: First part between bars is a date and second some identifiers |19511108|0001417| |19481024|0001439|... (6 Replies)
Discussion started by: maverick
6 Replies

Featured Tech Videos