How to remove /volumes/ from the automator service using existing shell script

automatorcommand linefinderterminal

I have this shell script from here. Right now it outputs something like this:

File Path: afp://serveraddress.com/Volumes/Sharepoint/Folder/test.txt Parent Folder: afp://serveraddress.com/Volumes/Sharepoint/Folder

If I were to paste this into a browser it fails because of the /Volumes/ portion of the output.

Is there a way to use this same output but strip the volumes from the output? My current code looks like this:

toTheClipboard="File Path: afp://serveraddress.com$(echo $1 | sed 's/ /%20/g') Parent Folder: afp://serveraddress.com$(dirname "$1" | sed 's/ /%20/g')"
pbcopy<<<"$toTheClipboard"

Best Answer

This is how I'd do it:

toTheClipboard="File Path: afp://serveraddress.com$(sed -e 's: :%20:g' -e 's:/Volumes::' <<< "$1") Parent Folder: afp://serveraddress.com$(dirname "$1" | sed -e 's: :%20:g' -e 's:/Volumes::')"
pbcopy<<<"$toTheClipboard"