I'm wanting to prepend the epoch time to a single line of arguments. My desired output is:
$ echo foo bar baz | some_bash_awk_sed_date_program_or_something_else
1491146539 foo bar baz
The actual output I'm getting can be seen below:
$ echo foo bar baz | awk -f time_stamper.awk
1491146539
0 foo bar baz
My time_stamper.awk:
BEGIN {
OFS=" "
printf "%s ", system("date +'%s'")
}
{ print }
I think the leading 0 is coming from the return value from date +'%s'. I was expecting setting the OFS=" " would at least return 1491146539 0 foo bar baz changing the newline to space.
Some questions about my current attempt:
- What is wrong with my usage of the
OFSbuilt-in variable? - Why is the
0printing in front offoo bar baz?
More importantly, I'm not sure if awk is the right tool for the job. Maybe I should use sed, date or some other utility.
- How do I print the desired output?
Note: This question is more specific and therefore different from this question. Also, the answer requires the installation of moreutils which seems like an interesting addition the Unix toolset; however, I'd rather stick with more traditional Unix utilities to perform my task.