0

I have a text file in linux as follows..All unique entries on ID..

Name ID Date
ABC 123 2019-07-01
DEF 456 2019-07-01
JKL 789 2019-09-01
XYZ 101 2019-02-01
TRN 107 2019-03-01

I want to filter results basis date(3rd column). For e.g i want to save all records before 2019-09-01 in another text file.

Please help.

  • What have you tried? What research did you do? Please read [ask]. https://www.tim-dennis.com/data/tech/2016/08/09/using-awk-filter-rows.html https://stackoverflow.com/questions/8734351/using-awk-to-filter-out-column-with-numerical-ranges no worries, your column is not numbers, but `>` in awk will compare them lexicographically with the same effect. – KamilCuk Apr 14 '21 at 07:22
  • tried `awk '{ if ($3 >= '2019-11-01' && $3 <= '2020-10-31') print $1 }' filename.txt` ... But it is not working.Giveing blank file. – Saurabh Deshpande Apr 14 '21 at 07:35
  • `'2019-11-01'` => `"2019-11-01"`. `2019 - 11 - 01 = 2007` research quoting in shell. and you do not want `2019-11-01` you want `2019-09-01 `... – KamilCuk Apr 14 '21 at 07:39

1 Answers1

0

i want to save all records before 2019-09-01 in another text file.

The following should just work:

awk '$3 < "2019-09-01"' filename.txt
KamilCuk
  • 120,984
  • 8
  • 59
  • 111