I have a hanging comma at the end of a file that I would like to replace with a close square bracket. There may or may not be a newline character at the end of the file as well. How can I replace the one or two characters with the square bracket using common unix tools?