Click here for important information about

Convert filename string into shell format

June 24, 2010 at 16:38:38
Specs: Macintosh
I am new to shell-scripting, and I have what should be a very simple problem to solve. Unfortunately, I have had no luck finding an answer.

I have a filename stored in a string, and I want to be able to use this with sed. In order for that to work, I need to change all instances of "." and "/" into "\." and "\/", respectively.

Is there a one-line command to do this? It seems that there has to be, since this must come up quite often. Thanks in advance for your help!

See More: Convert filename string into shell format

June 25, 2010 at 14:46:43
I'm not running Mac, but Solaris. The default sed seperator is / but I override it using | because I think it's easier to read:

echo "$mystring"|sed -e 's!\/!\\\/!g' -e 's|\.|\\\.|g'

Report •
Related Solutions

Ask Question