#!/bin/bash
path="/path/to/file 20-456 (1).jpg"
fldr="${path%/*}"   # Get the folder
file="${path##*/}"  # Get the file name
file="${file// /_}" # Replace spaces with underscores in filename
echo "$fldr/${file//[^[:alnum:]._-]/}" # Get the result
 