I am trying to write a script that removes everything after the last occurrence of a character. For example if the string is DATETIME 2014.03.14 12:23:24
, I would like to get just DATETIME 2014.03.
. So everything after the last occurrence of a dot should be stripped. I've been trying different variants with sed
and expr index
but without success. The last time I tried to get the index of the last dot and then substring it but without any result:
expr index "DATETIME 2014.03.14 12:23:24" '.[0-9][/&][0-9]'
This returns the position of the first dot instead of the last.