This seems like a common enough problem that it's probably a duplicate, but I could not find any other similar question.I have something like a log file that I append to, but I also want to keep it sorted, so I have something like this:echo foo >> file.txtLC_ALL=C sort -k1,1 -u -o file.txt file.txtIt's a really small file (<1000 lines), so the writing and sorting should be very quick. However, sometimes I have maybe 5 events per second, but some of them get lost. I was very surprised to see this problem with such low throughput application.Appending to file should work every time, so it's probably the sorting where the problem happens. I thought -o (write result to FILE instead of standard output) would take care of the concurrency issues, but maybe not.Is there a proper way of sorting a file if a different process might be writing to it?
sort a file in place while still writing to it
sort