1

Hello, I have this part of a script where I would like to get only the rows where the date (column 3) is older than the 10/30/2002 (format mm/dd/yyyy), but I'm not able to get the data correctly. I tried different things like store the value on a variable and call the $ or put it inside a () or like a string but nothing happens. The data type of the column $3 is "date".

Could you help me? How I am supposed to filter only for older values than that date?

#!/bin/bash
IFS=',' records=() sorted=()
{
    IFS='' read -r header

    while read -r -a values
    do
        [[ ${values[3]} < "10/30/2002" ]] || continue

        case....
Lauren Yim
  • 12,700
  • 2
  • 32
  • 59

1 Answers1

0

If you can't change the format, as mentioned in a comment, convert to seconds and use it in comparison (notice that the options to the date command can be different, this is for macOS)

#! /bin/bash

to_s() {
    local f='%m/%d/%Y %H:%M:%S'
    echo "$(date -ujf "$f" "$1 00:00:00" +'%s')"
}

s=$(to_s '10/30/2002')

while read -r -a values
do
    [[ $(to_s "${values[3]}") -lt $s ]] || continue
    # ...
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134