Reputation: 3213
I want to sort rows between time A
and time B
in format "00:00:00"
using awk shell script like (by just comparing the time columns of time directly) :
awk '{
if ("15:21:14" <= $1 && $1 <= "15:51:14")
{print $0}
}'
I got the right rows, but is it absolutely right for me to do this?
If not, what is the right way?
Upvotes: 1
Views: 373
Reputation: 204164
Assuming when you said "...I want to sort rows..." you really meant you want to SELECT rows, here's how to write that in awk:
awk '("15:21:14" <= $1) && ($1 <= "15:51:14")' file
This will work as long as all of your timestamps follow the same format and use a full 2 digits for every number, padding single-digit hours, for example, with a leading zero. If you want to sort the result then pipe the output to sort:
awk '("15:21:14" <= $1) && ($1 <= "15:51:14")' file | sort
Upvotes: 1