Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    Note that that assumes GNU date and that makes it a command injection vulnerability if the second field is not guaranteed to be a date. That also means forking one possible two processes per line and execute sh and date for each line of the file, so it going to be very inefficient. Commented Jul 4, 2023 at 6:47
  • 1
    nitpick - move months = "JanFebMarAprMayJunJulAugSepOctNovDec" into the BEGIN section so you do it once instead of once per input line. Commented Jul 4, 2023 at 10:38
  • 1
    Other nitpick - you could make the main part a bit more concise as {split($1, d, / /); month = index(months, d[2]) + 2) / 3; $1 = sprintf("%04d-%02d-%02d %s", d[6], month, d[3], d[4]); print} (not suggesting cramming it all on 1 line). Commented Jul 4, 2023 at 10:49
  • Thank you for the awk script. That did the job well. Commented Jul 4, 2023 at 22:34
  • I've noticed a small issue with the awk script. If the input file never contains a timestamp in the second field, then the awk command doesn't produce any output. the $2 != "" doesn't seem to fully act like an if statement, so if it doesn't match it just doesn't output the original line. Commented Jul 11, 2023 at 20:49