This content originally appeared on DEV Community and was authored by Query Filter
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 <date_col> <days_back> [delimiter]"
exit 1
fi
DATE_COL="$1"
DAYS="$2"
DELIM="${3:--}"
# FIXED: go BACK in time, not forward!
CUTOFF=$(date -d "$DAYS days ago" +%s)
awk -v col="$DATE_COL" -v cutoff="$CUTOFF" -F"$DELIM" '
function month2num(m) {
return (index("JanFebMarAprMayJunJulAugSepOctNovDec", m) + 2)/3
}
{
if (NF < col) next
d = $col
sub(/:[0-9]{3}/, "", d) # properly remove milliseconds
if (d !~ /AM|PM$/) d = d " " # ensure space before AM/PM if missing
match(d, /^([A-Za-z]{3})[[:space:]]+([0-9]{1,2})[[:space:]]+([0-9]{4})[[:space:]]+([0-9]{1,2}):([0-9]{2}):([0-9]{2})[[:space:]]+(AM|PM)/, a) || next
mon = month2num(toupper(a[1]))
ts = mktime(a[3] " " mon " " a[2] " " (a[4]+(a[7]=="PM" && a[4]<12?12:0)-(a[7]=="AM" && a[4]==12?12:0)) " " a[5] " " a[6])
if (ts >= cutoff) print
}
'
This content originally appeared on DEV Community and was authored by Query Filter
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Query Filter | Sciencx (2025-11-28T20:49:18+00:00) filter6. Retrieved from https://www.scien.cx/2025/11/28/filter6/
" » filter6." Query Filter | Sciencx - Friday November 28, 2025, https://www.scien.cx/2025/11/28/filter6/
HARVARDQuery Filter | Sciencx Friday November 28, 2025 » filter6., viewed ,<https://www.scien.cx/2025/11/28/filter6/>
VANCOUVERQuery Filter | Sciencx - » filter6. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/28/filter6/
CHICAGO" » filter6." Query Filter | Sciencx - Accessed . https://www.scien.cx/2025/11/28/filter6/
IEEE" » filter6." Query Filter | Sciencx [Online]. Available: https://www.scien.cx/2025/11/28/filter6/. [Accessed: ]
rf:citation » filter6 | Query Filter | Sciencx | https://www.scien.cx/2025/11/28/filter6/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.