Skip to main content
added 197 characters in body
Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

The system() function in awk run the command and return its status. You got 0 because the command is success. The output of date +'%s' was printed separately.

To get the output of external command, you would use getline():

$ echo foo bar baz | awk '{"date +%s" | getline d; printf "%s %s\n", d, $0}'
1491147643 foo bar baz

There's nothing to do with OFS, because it's a space by default.


With gawk or mawk, you can also do:

echo foo bar baz | gawk '{printf "%s %s\n", systime(), $0}'

The systime() return the number of seconds since epoch, not counting leap seconds


IOW, you can do it alone with date:

date +'%s foo bar baz'

The system() function in awk run the command and return its status. You got 0 because the command is success. The output of date +'%s' was printed separately.

To get the output of external command, you would use getline():

$ echo foo bar baz | awk '{"date +%s" | getline d; printf "%s %s\n", d, $0}'
1491147643 foo bar baz

There's nothing to do with OFS, because it's a space by default.


IOW, you can do it alone with date:

date +'%s foo bar baz'

The system() function in awk run the command and return its status. You got 0 because the command is success. The output of date +'%s' was printed separately.

To get the output of external command, you would use getline():

$ echo foo bar baz | awk '{"date +%s" | getline d; printf "%s %s\n", d, $0}'
1491147643 foo bar baz

There's nothing to do with OFS, because it's a space by default.


With gawk or mawk, you can also do:

echo foo bar baz | gawk '{printf "%s %s\n", systime(), $0}'

The systime() return the number of seconds since epoch, not counting leap seconds


IOW, you can do it alone with date:

date +'%s foo bar baz'
added 98 characters in body
Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

The system() function in awk run the command and return its status. You got 0 because the command is success. The output of date +'%s' was printed separately.

To get the output of external command, you would use getline()getline():

$ echo foo bar baz | awk '{"date +%s" | getline d; printf "%s %s\n", d, $0}'
1491147643 foo bar baz

There's nothing to do with OFS, because it's a space by default.


IOW, you can do it alone with date:

date +'%s foo bar baz'

The system() function in awk run the command and return its status. You got 0 because the command is success. The output of date +'%s' was printed separately.

To get the output of external command, you would use getline():

$ echo foo bar baz | awk '{"date +%s" | getline d; printf "%s %s\n", d, $0}'
1491147643 foo bar baz

There's nothing to do with OFS, because it's a space by default.


IOW, you can do it alone with date:

date +'%s foo bar baz'

The system() function in awk run the command and return its status. You got 0 because the command is success. The output of date +'%s' was printed separately.

To get the output of external command, you would use getline():

$ echo foo bar baz | awk '{"date +%s" | getline d; printf "%s %s\n", d, $0}'
1491147643 foo bar baz

There's nothing to do with OFS, because it's a space by default.


IOW, you can do it alone with date:

date +'%s foo bar baz'
Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

The system() function in awk run the command and return its status. You got 0 because the command is success. The output of date +'%s' was printed separately.

To get the output of external command, you would use getline():

$ echo foo bar baz | awk '{"date +%s" | getline d; printf "%s %s\n", d, $0}'
1491147643 foo bar baz

There's nothing to do with OFS, because it's a space by default.


IOW, you can do it alone with date:

date +'%s foo bar baz'