Using automation to update a field with bad data

I have a table in which users paste in the URL into a URL field, but they often paste in the wrong URL (https://example.com/edit/12345 is the right URL, and they paste in https://example.com/edit/12345#finished).

I currently have a formula that replaces the cruft and puts it in a new field (SUBSTITUTE({Link},"#finished","")), but I’d rather use automation to update the field in place. Can someone help me with the script I need to run?

Thanks!