0

I am running awk command to extract data from log file to calculate last 15 minutes log using below command and now i am getting bellow error:

awk '$0>=$from' from=$(`date -u +"####<%d-%b-%Y %H:%M:%S o'clock GMT>"-15min`) test.log

Error:

date: 0551-402 Invalid character in date/time specification.
Usage: date [-u] [+"Field Descriptors"]
awk: 0602-562 Field $() is not correct.
 The input line number is 1. The file is test.log.
 The source line number is 1.

Can anyone see what the problem is?

1
  • Remove extra back-tics Commented Mar 4, 2015 at 10:13

1 Answer 1

2

I believe you mean

awk '$0 >= from' from=$(date -u -d -15min "+####<%d-%b-%Y %H:%M:%S o'clock GMT>") test.log
  • $from in awk code does not mean the value of from but the fromth field. This does not make any sense if field is not a number.
  • the -15min in your date call are part of the format specifier, not the date spec.
  • Either backticks or $(), not both at the same time. Unless you want to run the output of date as a command and use the output of that.

By the way, I suspect that the lexicographical comparison of date strings formatted this way will not yield the result you want. It will not result in later dates being considered greater than earlier ones in all cases -- particularly at the end/beginning of months. 28-Feb is lexicographically greater than 01-Mar.

Addendum: Ah, I figured this seemed familiar. I left a solution to your previous question that does not have this problem before it was closed as a duplicate of something that doesn't really work for this case.

Sign up to request clarification or add additional context in comments.

2 Comments

Thats very informative Wintermute.Thank you :-) . How can i correct that i.e. for lexicographical comparison of date?
See my answer to your previous question (I linked to it). The basic idea is: instead of comparing the dates lexicographically, convert them to something that can be compared numerically, such as second since Epoch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.