extract lines using date range
I wish to extract lines from files based on date from first two fields eg: lines with todays date or week ago etc
eg of file: Jul 17 gfgf gfdg sdfg Jul 11 Jul 17 sdfd dfg Jul 11 fdf Jul 17 ffgg ggg Jul 16 gfg Jul 16 gfg ffg fdg Jul 17 I used awk suppose for todays date: k=`date '+%B %d'` awk -v m="$k" '($1,$2) == m' file For a week before: k=`date --date=="7 days ago" +%b\ %e` awk -v m="$k" '($1,$2) == m' file For user to enter date for search echo "enter month" read mon echo "enter date" read dat awk -v "m=$mon" "d=$dat" '$1 == m && $2 == d' file where am i going wrong in above scripts Also if there is other way i could do this |
# For Jul 19 - Find lines that have the string "Jul 19" in file.txt
Code:
grep "`date '+%b %d'`" file.txt Code:
grep "`date '+%b %d' --date='7 days ago'`" file.txt Code:
grep -E -e "`date '+%b %d'`|`date '+%b %d' --date='7 days ago'`" file.txt Code:
awk -v date="$(date +"%b %d")" '{if ($1" "$2==date) {print $0}}' file.txt Code:
awk -v date="$(date +"%b %d" --date="7 days ago")" '{if ($1" "$2==date) {print $0}}' file.txt Code:
awk -v date="$(date +"%b %d" --date="7 days ago")" -v date2="$(date +"%b %d")" '{if ($1" "$2==date || $1" "$2==date2) {print $0}}' file.txt Thanks |
thanks sydney was stuck for about two days
|
All times are GMT -5. The time now is 06:16 PM. |