I have a log file like Blah blah blah 2018-12-13. Now I want to grep the log files with a date before 2018-05-01. My intention is to filter the Log files lesser than 2018-05-01

closed as unclear what you're asking by Michael Homer, techraf, Satō Katsura, Archemar, countermode Oct 26 '16 at 8:14

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    does the date always occur at end of line? try awk '$NF < "2018-05-01"' – Sundeep Oct 26 '16 at 6:08
  • 4
    Add an example chunk, and your desired output from that. – heemayl Oct 26 '16 at 6:11
  • 1
    Is the spring "Blah blah blah 2018-12-13" a line in a log file or a name of a file? – Anton Leontiev Oct 26 '16 at 7:07

We can use awk's comparison operator

$ cat ip.txt 
Blah blah blah 2018-12-13
Blah blah blah 2018-02-13
Blah blah blah 2018-05-01

$ awk '$NF < "2018-05-01"' ip.txt 
Blah blah blah 2018-02-13

To get lines less than or equal to some date:

$ awk '$NF <= "2018-05-01"' ip.txt 
Blah blah blah 2018-02-13
Blah blah blah 2018-05-01

Using dategrep from dateutils, http://www.fresse.org/dateutils/

dategrep '<2018-05-01' <file

Not the answer you're looking for? Browse other questions tagged or ask your own question.