-1

Got command to Filter range of date from particular column of csv and but it does not work if both start and end date are same and input file has only one entry for that date

awk -v start="$start" -v end="$end" -F, '$2>=start && $2<=end' Inputfile 

works fine to filter date from 2nd column but if start="10/25/2017" and end="10/25/2017" and if the input file is (i.e only one entry for date "10/25/2017"), then no output is obtained

1,10/25/2017,Scheduled
3,11/1/2017,Scheduled
1,11/2/2017,Scheduled
3

1 Answer 1

2

I checked exacly your case and dat file. It works for me HOWEVER

  • AWK does not know date like this, so 9/30/2017 is higher than 10/1/2017. therefore the result could be very far from expected BECAUSE they are just strings!
  • "Military type timing", like 2017/09/30 and 2017/10/01 would work.
  • Separate month/day/year and compare them accordingly - but in this case I suggest perl rather than awk

Maybe it is a variable scope problem you have.

Try to use export start='10/25/2017' ; export end='10/25/2017' instead of start="10/25/2017" if you run awk in subshell for example.

4
  • Instead of the term "military type timing", you're looking for ISO 8601 -- en.wikipedia.org/wiki/ISO_8601#Calendar_dates Oct 24, 2017 at 21:14
  • @Glenn, I could have said "my timing" as well, because in Hungary we use this type of date... but you are abolutely true.
    – V-Mark
    Oct 24, 2017 at 22:08
  • You are correct. Awk does not know about dates. This answer is what mislead the questioner.
    – Wildcard
    Oct 24, 2017 at 23:08
  • @Wildcard LOOOL that "answer". There was also other, more correct answers... unfortunately with this date order a correct snippet is not an easy one-liner.
    – V-Mark
    Oct 25, 2017 at 8:51

Not the answer you're looking for? Browse other questions tagged .