A friend contacted me recently with an interesting question. We got something worked out, but I'm curious what answers you all can come up with.
Given a shell script (in bash) that processes a bunch of data and appends it to a file, how would you append the date, time, and a filename to the last line of the output?
Assume further that this has to happen separately from the part of the script that actually produces the data. It's a function that someone else wrote, and can't be changed. For what it's worth, I first suggested that some sort of time/date/file block be added at the start of the data file. But the requirements above are what my friend wanted, so that's the question.
Ahh, nice. I should have said "end up with it appended to the same data file that you're writing in the first place.
So, in pseudocode:
while (still have some input to handle)
generate_data() # writes to data1.txt
# ok we're done, add the date stamp
(some sort of sed magic) >> data1.txt