#!/bin/bash
# Usage: cat file.csv | ./filter_lastNdays.sh <date_column_number> <days>
# Example: cat file.csv | ./filter_lastNdays.sh 4 45
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <date_column_number> <days>"
exit 1
fi
DATE_COL="$1"
DAYS="$2"
# Calculate cutoff timestamp N days ago
CUTOFF=$(date -d "-$DAYS days" +%s)
awk -F'~' -v col="$DATE_COL" -v cutoff="$CUTOFF" '
{
ts = $col
# Remove milliseconds completely (:123)
ts = gensub(/:[0-9]{3}/, "", "g", ts)
# Ensure space before AM/PM
ts = gensub(/(AM|PM)$/, " \\1", "g", ts)
# Convert to epoch seconds
cmd = "date -d \"" ts "\" +%s"
cmd | getline t
close(cmd)
if(t >= cutoff) print
}'
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)