Skip to main content
added 298 characters in body
Source Link
terdon
  • 252.3k
  • 69
  • 480
  • 718

This has nothing to do with awk:

$ date -d  today  +%d/%m/%Y %H:%M
date: extra operand ‘%H:%M’
Try 'date --help' for more information.

The date command takes one argument, but you are giving it two: +%d/%m/%Y and %H:%M. The shell splits arguments on whitespace, so if you want that to be treated as a single argument, you need to quote it:

$ date -d  today  "+%d/%m/%Y %H:%M"
19/07/2024 11:14

So to get your awk command to work, you could do:

$ awk -F, '{system("date -d " $1 " \"+%d/%m/%Y %H:%M\"")}' file.log
19/07/2024 11:15

Or, alternatively, escape the space:

$ awk -F, '{system("date -d " $1 " +%d/%m/%Y\\ %H:%M")}' file.log
19/07/2024 19:30

Of the two, I prefer the quoting since that is also what you should do in the shell itself, so is a good habit to get into. Both should work fine here though.

You probably don't need this though. Since you're using date -d, you're probably on a GNU system and have GNU awk (gawk), so you can use its own date functions. See https://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html#Time-Functions.

This has nothing to do with awk:

$ date -d  today  +%d/%m/%Y %H:%M
date: extra operand ‘%H:%M’
Try 'date --help' for more information.

The date command takes one argument, but you are giving it two: +%d/%m/%Y and %H:%M. The shell splits arguments on whitespace, so if you want that to be treated as a single argument, you need to quote it:

$ date -d  today  "+%d/%m/%Y %H:%M"
19/07/2024 11:14

So to get your awk command to work, you could do:

$ awk -F, '{system("date -d " $1 " \"+%d/%m/%Y %H:%M\"")}' file.log
19/07/2024 11:15

You probably don't need this though. Since you're using date -d, you're probably on a GNU system and have GNU awk (gawk), so you can use its own date functions. See https://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html#Time-Functions.

This has nothing to do with awk:

$ date -d  today  +%d/%m/%Y %H:%M
date: extra operand ‘%H:%M’
Try 'date --help' for more information.

The date command takes one argument, but you are giving it two: +%d/%m/%Y and %H:%M. The shell splits arguments on whitespace, so if you want that to be treated as a single argument, you need to quote it:

$ date -d  today  "+%d/%m/%Y %H:%M"
19/07/2024 11:14

So to get your awk command to work, you could do:

$ awk -F, '{system("date -d " $1 " \"+%d/%m/%Y %H:%M\"")}' file.log
19/07/2024 11:15

Or, alternatively, escape the space:

$ awk -F, '{system("date -d " $1 " +%d/%m/%Y\\ %H:%M")}' file.log
19/07/2024 19:30

Of the two, I prefer the quoting since that is also what you should do in the shell itself, so is a good habit to get into. Both should work fine here though.

You probably don't need this though. Since you're using date -d, you're probably on a GNU system and have GNU awk (gawk), so you can use its own date functions. See https://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html#Time-Functions.

Source Link
terdon
  • 252.3k
  • 69
  • 480
  • 718

This has nothing to do with awk:

$ date -d  today  +%d/%m/%Y %H:%M
date: extra operand ‘%H:%M’
Try 'date --help' for more information.

The date command takes one argument, but you are giving it two: +%d/%m/%Y and %H:%M. The shell splits arguments on whitespace, so if you want that to be treated as a single argument, you need to quote it:

$ date -d  today  "+%d/%m/%Y %H:%M"
19/07/2024 11:14

So to get your awk command to work, you could do:

$ awk -F, '{system("date -d " $1 " \"+%d/%m/%Y %H:%M\"")}' file.log
19/07/2024 11:15

You probably don't need this though. Since you're using date -d, you're probably on a GNU system and have GNU awk (gawk), so you can use its own date functions. See https://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html#Time-Functions.