egorulz
egorulz

Reputation: 1505

awk variables don't work for date grep

 cat log | awk '/^Jun 14 11:52/,/^Jun 14 11:56/'

This works, it gives me the lines of log between those two timestamps.

cat log | awk -v start="$startTime" -v end="$endTime" '/^start/,/^end/'

This does NOT work. It returns empty.

Is there something wrong in the way I've used the awk variables?

Upvotes: 2

Views: 123

Answers (1)

anubhava
anubhava

Reputation: 785246

Between regex literals / and / you cannot use variables.

You can use:

awk -v start="$startTime" -v end="$endTime" '$0 ~ "^" start{p=1} p; $0 ~ "^" end{p=0}' log

Upvotes: 6

Related Questions